> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Nimble Extract

> [Nimble 的 Extract API](https://docs.nimbleway.com/nimble-sdk/extract-api) 通过使用无头浏览器浏览特定 URL 来提取已渲染的内容。与发现内容的搜索 API 不同，Extract 工具处理的是已知的 URL——非常适合需要获取和处理特定网页（包括分页、过滤器和客户端渲染背后的内容）的智能体工作流。

## 概述

### 集成详情

| 类                                                                    | 包                                                                | 可序列化 | JS 支持 |                                              包最新版本                                             |
| :------------------------------------------------------------------- | :--------------------------------------------------------------- | :--: | :---: | :--------------------------------------------------------------------------------------------: |
| [`NimbleExtractTool`](https://github.com/Nimbleway/langchain-nimble) | [`langchain-nimble`](https://pypi.org/project/langchain-nimble/) |   ❌  |   ❌   | ![PyPI - Version](https://img.shields.io/pypi/v/langchain-nimble?style=flat-square\&label=%20) |

### 工具特性

| 返回工件 | 原生异步 |                   返回数据                   |                  定价                  |
| :--: | :--: | :--------------------------------------: | :----------------------------------: |
|   ❌  |   ✅  | 标题、URL、内容（markdown/plain\_text/HTML）、元数据 | [提供免费试用](https://www.nimbleway.com/) |

**主要特性：**

* **URL 提取**：并行提取 1-20 个 URL 的已渲染内容
* **动态渲染**：处理 JavaScript、延迟加载和客户端渲染
* **多种格式**：plain\_text（默认）、markdown 或 simplified\_html
* **可配置的等待时间**：控制加载缓慢内容的页面加载行为
* **浏览器驱动程序**：可选择 vx6、vx8 或 vx10 驱动程序以满足不同的渲染需求
* **生产就绪**：原生异步支持、自动重试、连接池

## 设置

该集成位于 `langchain-nimble` 包中。

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install -U langchain-nimble
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv add langchain-nimble
  ```
</CodeGroup>

### 凭证

您需要一个 Nimble API 密钥才能使用此工具。在 [Nimble](https://www.nimbleway.com/) 注册以获取您的 API 密钥并访问其免费试用。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import getpass
import os

if not os.environ.get("NIMBLE_API_KEY"):
    os.environ["NIMBLE_API_KEY"] = getpass.getpass("Nimble API key:\n")
```

## 实例化

现在我们可以实例化该工具：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_nimble import NimbleExtractTool

# 基本用法
tool = NimbleExtractTool()
```

## 在智能体中使用

我们可以将 Nimble extract 工具与智能体结合使用，为其提供 URL 内容提取能力。以下是使用 LangGraph 的完整示例：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import os
import getpass

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")

# 初始化 Nimble Extract 工具
extract_tool = NimbleExtractTool(
    parsing_type="markdown"
)

# 使用该工具创建智能体
model = init_chat_model(model="gpt-4o", model_provider="openai", temperature=0)
agent = create_agent(model, [extract_tool])

# 要求智能体从 LangChain 文档中提取并分析内容
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/"

for step in agent.stream(
    {"messages": user_input},
    stream_mode="values",
):
    step["messages"][-1].pretty_print()
```

```output theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
================================ 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 提取的广泛配置：

| 参数             | 类型         | 默认值           | 描述                                                 |
| -------------- | ---------- | ------------- | -------------------------------------------------- |
| `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        | 环境变量          | Nimble API 密钥（默认为 NIMBLE\_API\_KEY 环境变量）           |

## 最佳实践

### 驱动程序选择

* **vx6**（默认）：适用于标准网站的快速提取
* **vx8**：适用于中等复杂网站的平衡性能
* **vx10**：适用于 JavaScript 密集型 SPA 和复杂动态内容的全面渲染

### 何时使用等待时间

* **无等待**（`wait=None`）：最适合大多数具有快速初始渲染的现代网站
* **短等待**（`wait=1000-2000`）：适用于具有延迟加载或动态内容的网站
* **较长等待**（`wait=5000+`）：适用于加载缓慢的页面或需要时间完全渲染的复杂 SPA 应用程序

### URL 管理

* **批量提取**：每次调用提供 1-20 个 URL 以并行提取
* **错误处理**：失败的 URL 将在智能体错误处理中报告
* **内容验证**：智能体应在处理前验证提取的内容

### 性能优化

* **选择合适的格式**：使用 **plain\_text** 以提高速度，使用 **markdown** 以保留结构，使用 **HTML** 以保留详细样式
* **调整等待时间**：仅在必要时使用等待时间以平衡速度和可靠性
* **批量处理相关 URL**：并行提取来自同一域的多个 URL 以提高效率
* **使用异步**：在并发提取多个 URL 时调用 `ainvoke()`

***

## API 参考

有关所有 `NimbleExtractTool` 功能和配置的详细文档，请访问 [Nimble API 文档](https://docs.nimbleway.com/nimble-sdk/search-api/extract-api-quick-start)。

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档连接](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/nimble_extract.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
