> ## 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.

# Tavily 获取研究集成

> 通过LangChain JavaScript与Tavily研究获取工具集成。

[Tavily](https://tavily.com/) 是专为 AI 智能体（LLM）构建的搜索引擎，能够快速提供实时、准确且真实的结果。Tavily 提供了一个 [Get Research](https://docs.tavily.com/documentation/api-reference/endpoint/research-get) 端点，通过请求 ID 检索先前创建的研究报告。

在 [TavilyResearch](https://langchain-docs-zh.mintlify.site/langchain/oss/javascript/integrations/tools/tavily_research.md) 后使用此工具，以轮询状态并获取完成结果。

## 概述

### 集成细节

| 类 | 包 | [PY 支持](https://langchain-docs-zh.mintlify.site/langchain/oss/python/integrations/tools/tavily_search.md) | 下载量 | 版本 |
| :- | :- | :-: | :-: | :-: |
| [`TavilyGetResearch`](https://reference.langchain.com/javascript/langchain-tavily/TavilyGetResearch) | [`@langchain/tavily`](https://www.npmjs.com/package/@langchain/tavily) | ✅ | ![NPM - 下载量](https://img.shields.io/npm/dm/@langchain/tavily?style=flat-square\&label=%20&) | ![NPM - 版本](https://img.shields.io/npm/v/@langchain/tavily?style=flat-square\&label=%20&) |

### 工具特性

| [返回工件](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/tools.md) | 原生异步 | 返回数据 | 定价 |
| :-: | :-: | :-: | :-: |
| ❌ | ✅ | 研究状态、报告内容、来源 | 每月 1,000 免费信用点 |

## 设置

集成位于 `@langchain/tavily` 包中：

```bash npm theme={null}
npm install @langchain/tavily @langchain/core
```

```bash yarn theme={null}
yarn add @langchain/tavily @langchain/core
```

```bash pnpm theme={null}
pnpm add @langchain/tavily @langchain/core
```

### 凭证

在 [Tavily 控制台](https://app.tavily.com) 上设置 API 密钥，并将其设置为名为 `TAVILY_API_KEY` 的环境变量。

```typescript theme={null}
process.env.TAVILY_API_KEY = "YOUR_API_KEY";
```

设置 [LangSmith](https://smith.langchain.com/) 以实现可观察性（但非必需）：

```typescript theme={null}
process.env.LANGSMITH_TRACING = "true";
process.env.LANGSMITH_API_KEY = "your-api-key";
```

## 实例化

您可以像这样导入和实例化 `TavilyGetResearch`：

```ts theme={null}
import { TavilyGetResearch } from "@langchain/tavily";

const tool = new TavilyGetResearch();
```

## 调用

### [直接使用参数调用](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/tools.md)

Tavily get research 工具在调用时接受以下参数：

* `requestId`（必需）：要检索的研究任务的唯一标识符

```ts theme={null}
await tool.invoke({
  requestId: "your-request-id-here",
});
```

### [使用 ToolCall 调用](https://langchain-docs-zh.mintlify.site/langchain/oss/langchain/tools.md)

您也可以使用模型生成的 `ToolCall` 调用该工具，此时会返回一个 @\[`ToolMessage`]：

```ts theme={null}
// This is usually generated by a model, but we'll create a tool call directly for demo purposes.
const modelGeneratedToolCall = {
  args: {
    requestId: "your-request-id-here",
  },
  id: "1",
  name: tool.name,
  type: "tool_call",
};

await tool.invoke(modelGeneratedToolCall);
```

## 在智能体中使用

将两个研究工具传递给 `createAgent`，以便智能体可以启动研究任务并通过请求 ID 检索结果：

```ts theme={null}
import { ChatOpenAI } from "@langchain/openai";
import { TavilyGetResearch, TavilyResearch } from "@langchain/tavily";
import { createAgent } from "langchain";

const llm = new ChatOpenAI({
  model: "gpt-5.5",
});

const agent = createAgent({
  model: llm,
  tools: [
    new TavilyResearch({
      model: "mini",
    }),
    new TavilyGetResearch(),
  ],
});

const userInput =
  "Start a research task on AI agents, then retrieve the results when ready.";

const stream = await agent.streamEvents(
  { messages: [{ role: "user", content: userInput }] },
  { version: "v3" },
);

await Promise.all([
  (async () => {
    for await (const message of stream.messages) {
      for await (const token of message.text) {
        process.stdout.write(token);
      }
    }
  })(),
  (async () => {
    for await (const call of stream.toolCalls) {
      console.dir({ name: call.name, input: call.input }, { depth: null });
      await call.output;
    }
  })(),
]);

await stream.output;
```

## API 参考

有关 Tavily Get Research API 所有特性和配置的详细文档，请参阅 API 参考：[docs.tavily.com/documentation/api-reference/endpoint/research-get](https://docs.tavily.com/documentation/api-reference/endpoint/research-get)

***

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


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