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

# 快速入门

> 几分钟内构建你的第一个 Deep Agent

本指南将引导你创建第一个具备规划、文件系统工具和子 Agent 功能的 Deep Agent。你将构建一个能够进行研究并撰写报告的研究 Agent。

<Tip>
  **正在使用 AI 编码助手？**

  * 安装 [LangChain 文档 MCP 服务器](/use-these-docs)，让你的 Agent 能够访问最新的 LangChain 文档和示例。
  * 安装 [LangChain Skills](https://github.com/langchain-ai/langchain-skills) 以提升你的 Agent 在 LangChain 生态系统任务上的表现。
</Tip>

## 前置条件

开始之前，请确保你拥有模型提供商的 API 密钥（例如 Gemini、Anthropic、OpenAI）。

<Note>
  Deep Agents 需要支持[工具调用](/oss/python/langchain/models#tool-calling)的模型。参阅[自定义配置](/oss/python/deepagents/customization#model)了解如何配置模型。
</Note>

## 步骤 1：安装依赖

<CodeGroup>
  ```bash pip theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  pip install deepagents tavily-python
  ```

  ```bash uv theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  uv init
  uv add deepagents tavily-python
  uv sync
  ```
</CodeGroup>

<Note>
  本指南使用 [Tavily](https://tavily.com/) 作为示例搜索服务提供商，但你可以替换为任何搜索 API（例如 DuckDuckGo、SerpAPI、Brave Search）。
</Note>

## 步骤 2：设置 API 密钥

<Tabs>
  <Tab title="Google">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    export GOOGLE_API_KEY="your-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"
    ```
  </Tab>

  <Tab title="OpenAI">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    export OPENAI_API_KEY="your-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"
    ```
  </Tab>

  <Tab title="Anthropic">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    export ANTHROPIC_API_KEY="your-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"
    ```
  </Tab>

  <Tab title="OpenRouter">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    export OPENROUTER_API_KEY="your-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"
    ```
  </Tab>

  <Tab title="Fireworks">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    export FIREWORKS_API_KEY="your-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"
    ```
  </Tab>

  <Tab title="Baseten">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    export BASETEN_API_KEY="your-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"
    ```
  </Tab>

  <Tab title="Ollama">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    # 本地：Ollama 必须在你的机器上运行
    # 云端：设置 Ollama API 密钥用于托管推理
    export OLLAMA_API_KEY="your-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"
    ```
  </Tab>

  <Tab title="其他">
    ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
    # 设置你的提供商的 API 密钥
    export <PROVIDER>_API_KEY="your-api-key"
    export TAVILY_API_KEY="your-tavily-api-key"
    ```

    Deep Agents 支持任何 [LangChain Chat Model](/oss/python/deepagents/models#supported-models)。请设置你所用提供商的 API 密钥。
  </Tab>
</Tabs>

## 步骤 3：创建搜索工具

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

from tavily import TavilyClient
from deepagents import create_deep_agent

tavily_client = TavilyClient(api_key=os.environ["TAVILY_API_KEY"])


def internet_search(
    query: str,
    max_results: int = 5,
    topic: Literal["general", "news", "finance"] = "general",
    include_raw_content: bool = False,
):
    """Run a web search"""
    return tavily_client.search(
        query,
        max_results=max_results,
        include_raw_content=include_raw_content,
        topic=topic,
    )
```

## 步骤 4：创建 Deep Agent

传入 `provider:model` 格式的 `model` 字符串，或[已初始化的模型实例](/oss/python/deepagents/models#configure-model-parameters)。参阅[支持的模型](/oss/python/deepagents/models#supported-models)了解所有提供商，以及[推荐模型](/oss/python/deepagents/models#suggested-models)查看经过测试的推荐方案。

<CodeGroup>
  ```python Google theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  # 用于引导 Agent 成为专业研究员的系统提示词
  research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.

  You have access to an internet search tool as your primary means of gathering information.

  ## `internet_search`

  Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
  """

  agent = create_deep_agent(
      model="google_genai:gemini-3.1-pro-preview",
      tools=[internet_search],
      system_prompt=research_instructions,
  )
  ```

  ```python OpenAI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  # 用于引导 Agent 成为专业研究员的系统提示词
  research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.

  You have access to an internet search tool as your primary means of gathering information.

  ## `internet_search`

  Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
  """

  agent = create_deep_agent(
      model="openai:gpt-5.4",
      tools=[internet_search],
      system_prompt=research_instructions,
  )
  ```

  ```python Anthropic theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  # 用于引导 Agent 成为专业研究员的系统提示词
  research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.

  You have access to an internet search tool as your primary means of gathering information.

  ## `internet_search`

  Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
  """

  agent = create_deep_agent(
      model="anthropic:claude-sonnet-4-6",
      tools=[internet_search],
      system_prompt=research_instructions,
  )
  ```

  ```python OpenRouter theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  # 用于引导 Agent 成为专业研究员的系统提示词
  research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.

  You have access to an internet search tool as your primary means of gathering information.

  ## `internet_search`

  Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
  """

  agent = create_deep_agent(
      model="openrouter:anthropic/claude-sonnet-4-6",
      tools=[internet_search],
      system_prompt=research_instructions,
  )
  ```

  ```python Fireworks theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  # 用于引导 Agent 成为专业研究员的系统提示词
  research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.

  You have access to an internet search tool as your primary means of gathering information.

  ## `internet_search`

  Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
  """

  agent = create_deep_agent(
      model="fireworks:accounts/fireworks/models/qwen3p5-397b-a17b",
      tools=[internet_search],
      system_prompt=research_instructions,
  )
  ```

  ```python Baseten theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  # 用于引导 Agent 成为专业研究员的系统提示词
  research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.

  You have access to an internet search tool as your primary means of gathering information.

  ## `internet_search`

  Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
  """

  agent = create_deep_agent(
      model="baseten:zai-org/GLM-5",
      tools=[internet_search],
      system_prompt=research_instructions,
  )
  ```

  ```python Ollama theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  # 用于引导 Agent 成为专业研究员的系统提示词
  research_instructions = """You are an expert researcher. Your job is to conduct thorough research and then write a polished report.

  You have access to an internet search tool as your primary means of gathering information.

  ## `internet_search`

  Use this to run an internet search for a given query. You can specify the max number of results to return, the topic, and whether raw content should be included.
  """

  agent = create_deep_agent(
      model="ollama:devstral-2",
      tools=[internet_search],
      system_prompt=research_instructions,
  )
  ```
</CodeGroup>

## 步骤 5：运行 Agent

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
result = agent.invoke({"messages": [{"role": "user", "content": "What is langgraph?"}]})

# 打印 Agent 的响应
print(result["messages"][-1].content)
```

<Tip>
  使用 [LangSmith](https://smith.langchain.com?utm_source=docs\&utm_medium=cta\&utm_campaign=langsmith-signup\&utm_content=oss-deepagents-quickstart) 追踪你的 Agent 的规划步骤、工具调用和子 Agent 委派。按照[可观测性快速入门](/langsmith/observability-quickstart)进行设置。
</Tip>

## 工作原理

你的 Deep Agent 会自动执行以下操作：

1. **规划方法**，使用内置的 [`write_todos`](/oss/python/deepagents/harness#planning-capabilities) 工具将研究任务分解。
2. **进行研究**，通过调用 `internet_search` 工具收集信息。
3. **管理上下文**，使用文件系统工具（[`write_file`](/oss/python/deepagents/harness#virtual-filesystem-access)、[`read_file`](/oss/python/deepagents/harness#virtual-filesystem-access)）卸载大型搜索结果。
4. **生成子 Agent**，根据需要将复杂子任务委派给专门的子 Agent。
5. **合成报告**，将研究结果整合为连贯的响应。

## 示例

有关可以使用 Deep Agents 构建的 Agent、模式和应用程序，请参阅[示例](https://github.com/langchain-ai/deepagents/tree/main/examples)。

## Streaming

Deep Agents 内置了 [Streaming](/oss/python/langchain/event-streaming) 功能，可使用 LangGraph 实时获取 Agent 执行过程的更新。
这使你能够逐步观察输出，并审查和调试 Agent 及子 Agent 的工作，如工具调用、工具结果和 LLM 响应。

## 后续步骤

现在你已经构建了第一个 Deep Agent：

* **自定义你的 Agent**：了解[自定义选项](/oss/python/deepagents/customization)，包括自定义系统提示词、工具和子 Agent。
* **添加长期记忆**：启用跨对话的[持久化记忆](/oss/python/deepagents/memory)。
* **部署到生产环境**：使用[托管 Deep Agents](/langsmith/deploy-managed-deep-agent) 在 LangSmith 中创建、运行和操作 Deep Agents。

***

<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/deepagents/quickstart.mdx)或[提交 Issue](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
