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

# 并行 FindAll 集成

> 使用 LangChain Python 集成 ParallelFindAllTool 工具。

> [并行](https://platform.parallel.ai/)是一个为大型语言模型（LLM）和AI应用构建的实时网络搜索和内容提取平台。

`ParallelFindAllTool`调用并行的[FindAll API](https://docs.parallel.ai/findall-api/findall-quickstart)进行实体发现。给定一个自然语言目标和布尔匹配条件列表，它返回满足所有条件的排名候选者。

## 概述

### 集成细节

| 类 | 包 | 可序列化 | JS支持 | 最新包版本 |
| :- | :- | :-: | :-: | :-: |
| @\[`ParallelFindAllTool`] | @\[`langchain-parallel`] | ❌ | ❌ | [![PyPI - Latest version](https://img.shields.io/pypi/v/langchain-parallel?style=flat-square\&label=%20\&color=orange)](https://pypi.org/project/langchain-parallel/) |

## 设置

集成存在于`langchain-parallel`包中。

```bash pip theme={null}
pip install -U langchain-parallel
```

```bash uv theme={null}
uv add langchain-parallel
```

### 凭证

前往[并行](https://platform.parallel.ai)注册并生成API密钥。在您的环境中设置`PARALLEL_API_KEY`：

```python theme={null}
import getpass
import os

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

## 实例化

`generator`是一个工具级设置。使用`"preview"`（免费，限制为10个候选者）进行快速迭代；切换到`"base"`（默认），`"core"`或`"pro"`以获得更高质量的运行。

```python theme={null}
from langchain_parallel import ParallelFindAllTool

tool = ParallelFindAllTool(generator="preview")
```

## 调用

### 快速发现（预览生成器）

`preview`生成器在几秒钟内返回，并限制为10个候选者。`match_limit`是必需的；对于`preview`，它必须在`[5, 10]`中。

```python theme={null}
from langchain_parallel import FindAllMatchCondition

result = await tool.ainvoke({
    "objective": "Pure-play public LLM API providers",
    "entity_type": "company",
    "match_conditions": [
        FindAllMatchCondition(
            name="public_us",
            description="Company is publicly traded on a US exchange",
        ),
        FindAllMatchCondition(
            name="llm_api_revenue",
            description="Primary revenue is selling LLM inference via API",
        ),
    ],
    "match_limit": 5,
})

for c in result["candidates"]:
    print(c["name"], "—", c["url"])
```

```text theme={null}
Anthropic — https://www.anthropic.com
OpenAI — https://www.openai.com
...
```

### 更高质量的运行

切换到`"base"`、`"core"`或`"pro"`以获得高达1000个的`match_limit`。这些需要几分钟；工具会轮询，直到运行达到终端状态（`completed`、`cancelled`或`failed`）。

```python theme={null}
deep = ParallelFindAllTool(generator="core")

result = await deep.ainvoke({
    "objective": "Independent solar-installer companies based in the EU",
    "entity_type": "company",
    "match_conditions": [
        FindAllMatchCondition(
            name="eu_hq",
            description="Headquartered in an EU country",
        ),
        FindAllMatchCondition(
            name="residential_solar_pv",
            description="Primarily installs residential solar PV",
        ),
    ],
    "match_limit": 50,
})
```

### 排除已处理的候选者

传递`exclude_list=[FindAllExcludeEntry(name=..., url=...)]`以丢弃您已经处理的候选者。`name`和`url`都是必需的。

```python theme={null}
from langchain_parallel import FindAllExcludeEntry

result = await tool.ainvoke({
    "objective": "Pure-play public LLM API providers",
    "entity_type": "company",
    "match_conditions": [
        FindAllMatchCondition(
            name="llm_api_revenue",
            description="Primary revenue is selling LLM inference via API",
        ),
    ],
    "match_limit": 5,
    "exclude_list": [
        FindAllExcludeEntry(name="OpenAI", url="https://www.openai.com"),
        FindAllExcludeEntry(name="Anthropic", url="https://www.anthropic.com"),
    ],
})
```

### 取消

`cancel()`通过ID中止正在运行的运行。ID返回给启动运行的调用者；如果您使用`tool.ainvoke(...)`在一个长时间运行的任务中启动它，从运行中捕获`findall_id`，然后等待完成。

```python theme={null}
# from another task / handler:
tool.cancel(findall_id)        # sync
await tool.acancel(findall_id) # async
```

### 参数

#### 必填

* `objective`：要查找的自然语言描述。
* `entity_type`：描述候选者类别的简短名词（`"company"`、`"researcher"`、`"product"`等）。
* `match_conditions`：`FindAllMatchCondition(name=..., description=...)`列表。每个字段都需要这两个字段。
* `match_limit`：`[5, 1000]`中的整数。`preview`生成器进一步将其限制为10。

#### 可选

* `exclude_list`：要跳过的`FindAllExcludeEntry(name=..., url=...)`列表。
* `webhook`：接收运行/候选者事件的`FindAllWebhook(url=..., event_types=[...])`。
* `metadata`：保存在运行上的自由形式元数据。
* `timeout`：秒级轮询超时（默认600）。

## 链接

将工具绑定到任何工具调用对话模型，并使用[`create_agent`](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/agents)驱动智能体：

```python theme={null}
from langchain.agents import create_agent
from langchain.chat_models import init_chat_model

llm = init_chat_model(model="claude-haiku-4-5", model_provider="anthropic")
agent = create_agent(model=llm, tools=[tool])

agent.invoke({"messages": [("human", "Find me a few independent EU solar installers.")]})
```

## 响应格式

```python theme={null}
{
    "candidates": [
        {
            "candidate_id": "cand_abc",
            "name": "Acme Solar",
            "url": "https://acmesolar.example",
            "description": "...",
            "match_status": "matched",  # or "generated" / "unmatched"
            "output": {
                "<condition_name>": {
                    "type": "match_condition",
                    "value": True,
                    "is_matched": True,
                },
            },
            "basis": [...],  # citations + reasoning per output field
        },
    ],
    "run": {...},          # status info
    "last_event_id": "...",
}
```

## API参考

有关详细文档，请前往 @\[`ParallelFindAllTool`] API参考或[并行FindAll API指南](https://docs.parallel.ai/findall-api/findall-quickstart)。

***

> 官方原文：[src/oss/python/integrations/tools/parallel\_findall.mdx](https://github.com/langchain-ai/docs/blob/main/src/oss/python/integrations/tools/parallel_findall.mdx) · 非官方翻译，译文由 AI 生成，以英文原文为准。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.