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

# 模型

> 为 Deep Agents 配置模型提供商和参数

Deep Agents 可与任何支持[工具调用](/oss/python/langchain/models#tool-calling)的 [LangChain 聊天模型](/oss/python/langchain/models)配合使用。

## 支持的模型

以 `提供商:模型` 格式指定模型（例如 `google_genai:gemini-3.1-pro-preview`、`openai:gpt-5.4` 或 `anthropic:claude-sonnet-4-6`）。提供商前缀选择 LangChain 集成，冒号后的所有内容将作为模型标识符传递给该提供商。有关有效的提供商字符串，请参阅 [`init_chat_model`](https://reference.langchain.com/python/langchain/chat_models/base/init_chat_model) 的 `model_provider` 参数。有关提供商特定配置，请参阅[聊天模型集成](/oss/python/integrations/chat)。

模型标识符必须符合提供商预期的格式。某些提供商使用简单名称（如 `gpt-5.4`）；其他提供商使用带命名空间的 ID 或部署路径（如 `zai-org/GLM-5.1`），因此完整的 Deep Agents 字符串将是 `baseten:zai-org/GLM-5.1`。请查阅提供商的模型目录或集成文档以获取当前标识符。

### 推荐模型

这些模型在 [Deep Agents 评估套件](https://github.com/langchain-ai/deepagents/tree/main/libs/evals#readme)中表现良好，该套件测试基本代理操作。通过这些评估是必要条件，但不足以确保在更长、更复杂的任务中表现出色。

| 提供商                                                       | 模型                                                                                                                                 |
| --------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| [Google](/oss/python/integrations/providers/google)       | `gemini-3.1-pro-preview`、`gemini-3-flash-preview`                                                                                  |
| [OpenAI](/oss/python/integrations/providers/openai)       | `gpt-5.4`、`gpt-4o`、`gpt-5.4`、`o4-mini`、`gpt-5.2-codex`、`gpt-4o-mini`、`o3`                                                          |
| [Anthropic](/oss/python/integrations/providers/anthropic) | `claude-opus-4-6`、`claude-opus-4-5`、`claude-sonnet-4-6`、`claude-sonnet-4`、`claude-sonnet-4-5`、`claude-haiku-4-5`、`claude-opus-4-1` |
| 开放权重                                                      | `GLM-5`、`Kimi-K2.5`、`MiniMax-M2.5`、`qwen3.5-397B-A17B`、`devstral-2-123B`                                                           |

开放权重模型可通过 [Baseten](/oss/python/integrations/providers/baseten)、[Fireworks](/oss/python/integrations/providers/fireworks)、[OpenRouter](/oss/python/integrations/providers/openrouter) 和 [Ollama](/oss/python/integrations/providers/ollama) 等提供商使用。

## 配置模型参数

将模型字符串以 `提供商:模型` 格式传递给 [`create_deep_agent`](https://reference.langchain.com/python/deepagents/graph/create_deep_agent)，或传递已配置的模型实例以进行完全控制。在底层，模型字符串通过 [`init_chat_model`](https://reference.langchain.com/python/langchain/chat_models/base/init_chat_model) 解析。

要配置模型特定参数，请使用 [`init_chat_model`](https://reference.langchain.com/python/langchain/chat_models/base/init_chat_model) 或直接实例化提供商模型类：

<CodeGroup>
  ```python init_chat_model theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  from langchain.chat_models import init_chat_model
  from deepagents import create_deep_agent

  model = init_chat_model(
      model="google_genai:gemini-3.1-pro-preview",
      thinking_level="medium",  # [!code highlight]
  )
  agent = create_deep_agent(model=model)
  ```

  ```python Provider package theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
  from langchain_google_genai import ChatGoogleGenerativeAI
  from deepagents import create_deep_agent

  model = ChatGoogleGenerativeAI(
      model="gemini-3.1-pro-preview",
      thinking_level="medium",  # [!code highlight]
  )
  agent = create_deep_agent(model=model)
  ```
</CodeGroup>

<Note>
  可用参数因提供商而异。有关提供商特定的配置选项，请参阅[聊天模型集成](/oss/python/integrations/chat)页面。
</Note>

### 提供商配置文件

[`ProviderProfile`](/oss/python/deepagents/profiles#provider-profiles) 封装了在创建深度代理时提供 `提供商:模型` 字符串时应用的初始化参数。当您传递使用 [`init_chat_model`](https://reference.langchain.com/python/langchain/chat_models/base/init_chat_model) 预配置的模型时，它不适用。

您可以在两个级别注册，两者可以共存：

* **提供商级别** — 裸提供商键（如 `"openai"`）适用于来自 `openai` 提供商的每个模型。
* **模型级别** — `提供商:模型` 键（如 `"openai:gpt-5.4"`）仅适用于该特定模型，并在任何匹配的提供商级别配置文件之上合并。

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from deepagents import ProviderProfile, register_provider_profile

# Provider-wide default: every openai model gets temperature=0.
register_provider_profile(
    "openai",
    ProviderProfile(init_kwargs={"temperature": 0}),
)

# Model-level override: gpt-5.4 additionally gets a specific reasoning effort.
# Inherits temperature=0 from the provider-level profile above.
register_provider_profile(
    "openai:gpt-5.4",
    ProviderProfile(init_kwargs={"reasoning_effort": "medium"}),
)
```

有关完整字段列表、合并语义和插件封装，请参阅[配置文件](/oss/python/deepagents/profiles)。

<Tip>
  要塑造模型构建后*代理*的行为方式，请使用[测试工具配置文件](/oss/python/deepagents/profiles#harness-profiles)。
</Tip>

## 在运行时选择模型

如果您的应用程序允许用户选择模型（例如在 UI 中使用下拉菜单），请使用[中间件](/oss/python/langchain/middleware)在运行时交换模型，而无需重建代理。

通过[运行时上下文](/oss/python/langchain/agents#dynamic-model)传递用户的选择，然后使用 `wrap_model_call` 中间件在每次调用时使用 [`@wrap_model_call`](https://reference.langchain.com/python/langchain/agents/middleware/types/wrap_model_call) 装饰器覆盖模型：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from dataclasses import dataclass
from langchain.chat_models import init_chat_model
from langchain.agents.middleware import wrap_model_call, ModelRequest, ModelResponse
from deepagents import create_deep_agent
from typing import Callable


@dataclass
class Context:
    model: str

@wrap_model_call
def configurable_model(
    request: ModelRequest,
    handler: Callable[[ModelRequest], ModelResponse],
) -> ModelResponse:
    model_name = request.runtime.context.model
    model = init_chat_model(model_name)
    return handler(request.override(model=model))

agent = create_deep_agent(
    model="google_genai:gemini-3.1-pro-preview",
    middleware=[configurable_model],
    context_schema=Context,
)

# Invoke with the user's model selection
result = agent.invoke(
    {"messages": [{"role": "user", "content": "Hello!"}]},
    context=Context(model="openai:gpt-5.4"),
)
```

<Tip>
  有关更多动态模型模式（例如基于对话复杂性或成本优化进行路由），请参阅 LangChain 代理指南中的[动态模型](/oss/python/langchain/agents#dynamic-model)。
</Tip>

## 了解更多

* [LangChain 中的模型](/oss/python/langchain/models)：聊天模型功能，包括工具调用、结构化输出和多模态

***

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