>Nimble 的 Extract API 通过无头浏览器浏览特定 URL 来提取渲染内容。与发现内容的搜索 API 不同,Extract 工具处理已知 URL——非常适合需要获取和处理特定网页内容的代理工作流,包括分页、过滤器和客户端渲染背后的内容。
概述
集成详情
| Class | Package | Serializable | JS support | Package latest |
|---|---|---|---|---|
NimbleExtractTool | langchain-nimble | ❌ | ❌ | !PyPI - 版本 |
工具特性
| Returns artifact | Native async | Return data | Pricing |
|---|---|---|---|
| ❌ | ✅ | title, URL, content (markdown/plain_text/HTML), metadata | 提供免费试用 |
主要特性:
- URL 提取:并行从 1-20 个 URL 提取渲染内容
- 动态渲染:处理 JavaScript、延迟加载和客户端渲染
- 多种格式:plain_text(默认)、markdown 或 simplified_html
- 可配置的等待时间:控制慢加载内容的页面加载行为
- 浏览器驱动:选择 vx6、vx8 或 vx10 驱动以满足不同的渲染需求
- Production-ready:原生异步支持、自动重试、连接池
设置
该集成位于 langchain-nimble package.
pip install -U langchain-nimble
uv add langchain-nimble
凭据
您需要 Nimble API 密钥才能使用此工具。在 Nimble 注册以获取您的 API 密钥并访问他们的免费试用版。
if not os.environ.get("NIMBLE_API_KEY"):
os.environ["NIMBLE_API_KEY"] = getpass.getpass("Nimble API key:\n")
实例化
现在我们可以实例化该工具:
from langchain_nimble import NimbleExtractTool
# Basic usage
tool = NimbleExtractTool()
在代理中使用
我们可以将 Nimble 提取工具与代理一起使用,为其提供 URL 内容提取能力。以下是使用 LangGraph 的完整示例:
from langchain_nimble import NimbleExtractTool
from langchain.agents import create_agent
from langchain.chat_models import init_chat_model
if not os.environ.get("OPENAI_API_KEY"):
os.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API key:\n")
if not os.environ.get("NIMBLE_API_KEY"):
os.environ["NIMBLE_API_KEY"] = getpass.getpass("Nimble API key:\n")
# Initialize Nimble Extract Tool
extract_tool = NimbleExtractTool(
parsing_type="markdown"
)
# Create agent with the tool
model = init_chat_model(model="gpt-4o", model_provider="openai", temperature=0)
agent = create_agent(model, [extract_tool])
# Ask the agent to extract and analyze content from LangChain documentation
user_input = "Extract and summarize the key concepts from these LangChain docs: https://python.langchain.com/docs/concepts/retrievers/, https://python.langchain.com/docs/concepts/tools/"
stream = agent.stream_events({"messages": user_input}, version="v3")
for snapshot in stream.values:
snapshot["messages"][-1].pretty_print()
================================ Human Message =================================
Extract and summarize the key concepts from these LangChain docs: https://python.langchain.com/docs/concepts/retrievers/, https://python.langchain.com/docs/concepts/tools/
================================== Ai Message ==================================
Tool Calls:
nimble_extract (call_abc123)
Call ID: call_abc123
Args:
links: ['https://python.langchain.com/docs/concepts/retrievers/', 'https://python.langchain.com/docs/concepts/tools/']
parsing_type: markdown
================================= Tool Message =================================
Name: nimble_extract
[{"title": "Retrievers | LangChain", "url": "https://python.langchain.com/docs/concepts/retrievers/", "content": "# Retrievers\n\nA retriever is an interface that returns documents given an unstructured query...\n\n## Key Concepts\n- Document retrieval from various sources\n- Integration with vector stores...", "metadata": {"extracted_at": "2025-12-10T..."}}, {"title": "Tools | LangChain", "url": "https://python.langchain.com/docs/concepts/tools/", "content": "# Tools\n\nTools are interfaces that agents can use to interact with the world...", "metadata": {...}}]
================================== Ai Message ==================================
Based on the extracted LangChain documentation, here are the key concepts:
**Retrievers:**
- Interface for returning documents based on unstructured queries
- Supports various data sources including vector stores
- Core component for RAG (Retrieval Augmented Generation) applications
- Enables semantic search over document collections
**Tools:**
- Interfaces enabling agents to interact with external systems
- Can be used for web search, API calls, calculations, and more
- Agents use tools to extend their capabilities beyond text generation
- Support both synchronous and asynchronous execution
高级配置
该工具支持广泛的 URL 提取配置:
| Parameter | Type | Default | Description |
|---|---|---|---|
links | list[str] | None | 要提取的 URL (1-20) - 由代理在运行时提供 |
parsing_type | str | "plain_text" | 输出格式:"plain_text"、"markdown" 或 "simplified_html" |
driver | str | "vx6" | 浏览器驱动版本:"vx6"(快速)、"vx8"(均衡)或 "vx10"(全面) |
wait | int | None | 等待页面加载的毫秒数 (0-60000) |
render | bool | True | 启用 JavaScript 渲染 |
locale | str | "en" | 页面语言区域偏好(例如 "en-US") |
country | str | "US" | 本地化内容的国家代码(例如 "US") |
api_key | str | env var | Nimble API 密钥(默认使用 NIMBLE_API_KEY 环境变量) |
最佳实践
驱动程序选择
- vx6 (默认):针对标准网站的快速提取
- vx8:针对中等复杂网站的均衡性能
- vx10:针对重度 JavaScript 的 SPA 和复杂动态内容的全面渲染
何时使用等待时间
- 无等待 (
wait=None):最适合具有快速初始渲染的大多数现代网站 - 短等待 (
wait=1000-2000):适用于具有懒加载或动态内容的网站 - 较长等待 (
wait=5000+):适用于需要完全渲染时间的慢加载页面或复杂 SPA 应用程序
URL 管理
- 批量提取:每次调用提供 1-20 个 URL 进行并行提取
- 错误处理:失败的 URL 将在代理错误处理中报告
- 内容验证:代理应在处理前验证提取的内容
性能优化
- 选择适当的格式:使用 **纯文本_文本** 以提高速度, **Markdown** 以保持结构, **HTML** 以获得详细样式
- 调整等待时间:仅在必要时使用等待时间以平衡速度和可靠性
- 批量处理相关 URL:从同一域并行提取多个 URL 以提高效率
- 使用异步:调用
ainvoke()以实现高吞吐量
API 参考
有关所有 NimbleExtractTool 功能和配置的详细文档,请访问 Nimble API 文档.