Skip to content
LangChain 文档版本 跟随上游 源快照 7e778ca4 更新于 2026-10-08

模型

为 Deep Agents 配置模型服务商和参数

Deep Agents 可与任何支持 工具调用 的 LangChain 聊天模型 配合使用。

支持的模型

以 provider:model 格式指定模型(例如 google_genai:gemini-3.6-flash、openai:gpt-5.4 或 anthropic:claude-sonnet-4-6)。provider 前缀用于选择 LangChain 集成,冒号之后的所有内容都会作为模型标识符传递给该服务商。有关有效的 provider 字符串,请参阅 init_chat_model 的 model_provider 参数。有关服务商特定的配置,请参阅 聊天模型集成。

模型标识符必须与服务商期望的格式相匹配。有些服务商使用像 gpt-5.5 这样的简单名称;另一些则使用带命名空间的 ID 或像 zai-org/GLM-5.2 这样的部署路径,因此完整的 Deep Agents 字符串会是 baseten:zai-org/GLM-5.2。请查看服务商的模型目录或集成文档以获取当前的标识符。

推荐模型

这些模型在 Deep Agents 评估套件 上表现良好,该套件测试基本的智能体操作。通过这些评估是在更长、更复杂的任务上取得出色表现的必要条件,但并非充分条件。

服务商模型
Googlegemini-3.1-pro-preview、gemini-3.6-flash
OpenAIgpt-5.5、gpt-5.4
Anthropicclaude-opus-4-8、claude-opus-4-7、claude-opus-4-6
开放权重GLM-5.2、Kimi-K2.7 Code、MiniMax-M3

开放权重模型可通过 Baseten、Fireworks、OpenRouter 和 Ollama 等服务商获取。

模型评估

Deep Agents 评估套件 测试了流行的模型:

| 模型 | 总体 | 文件操作 | 检索 | 工具使用 | 记忆 | 对话 | 摘要 | | :- | -: | -: | -: | -: | -: | -: | -: | | google\_genai:gemini-3.6-flash | [82%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | **[90%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | [54%](https://github.com/langchain-ai/deepagents/actions/runs/25290479270) | [38%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | | openai:gpt-5.4 | [18%](https://github.com/langchain-ai/deepagents/actions/runs/24906955930) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/24172638583)** | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/24172638583)** | [18%](https://github.com/langchain-ai/deepagents/actions/runs/24906955930) | [51%](https://github.com/langchain-ai/deepagents/actions/runs/24172638583) | [38%](https://github.com/langchain-ai/deepagents/actions/runs/24425363630) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/24172638583)** | | openai:gpt-5.5 | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | [92%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | [84%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | [64%](https://github.com/langchain-ai/deepagents/actions/runs/25345307822) | **[52%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | | anthropic:claude-opus-4-6 | [26%](https://github.com/langchain-ai/deepagents/actions/runs/24906955930) | [92%](https://github.com/langchain-ai/deepagents/actions/runs/24172638583) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/24172638583)** | [26%](https://github.com/langchain-ai/deepagents/actions/runs/24906955930) | **[69%](https://github.com/langchain-ai/deepagents/actions/runs/24172638583)** | [22%](https://github.com/langchain-ai/deepagents/actions/runs/24363491527) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/24172638583)** | | anthropic:claude-opus-4-7 | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | [82%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | — | [48%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | | baseten:moonshotai/Kimi-K2.6 | [79%](https://github.com/langchain-ai/deepagents/actions/runs/25475600906) | [92%](https://github.com/langchain-ai/deepagents/actions/runs/25475600906) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25475600906)** | [84%](https://github.com/langchain-ai/deepagents/actions/runs/25475600906) | — | [43%](https://github.com/langchain-ai/deepagents/actions/runs/25475600906) | [60%](https://github.com/langchain-ai/deepagents/actions/runs/25475600906) | | baseten:zai-org/GLM-5 | [77%](https://github.com/langchain-ai/deepagents/actions/runs/25403850424) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25403850424)** | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25403850424)** | [89%](https://github.com/langchain-ai/deepagents/actions/runs/25403850424) | [44%](https://github.com/langchain-ai/deepagents/actions/runs/23872647281) | [24%](https://github.com/langchain-ai/deepagents/actions/runs/25403850424) | [60%](https://github.com/langchain-ai/deepagents/actions/runs/25403850424) | | fireworks:accounts/fireworks/models/glm-5p1 | [81%](https://github.com/langchain-ai/deepagents/actions/runs/25461031650) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25461031650)** | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25461031650)** | [87%](https://github.com/langchain-ai/deepagents/actions/runs/25461031650) | — | [33%](https://github.com/langchain-ai/deepagents/actions/runs/25461031650) | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25461031650) | | fireworks:accounts/fireworks/models/minimax-m2p7 | [79%](https://github.com/langchain-ai/deepagents/actions/runs/25403894412) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25403894412)** | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25403894412)** | [85%](https://github.com/langchain-ai/deepagents/actions/runs/25403894412) | — | [43%](https://github.com/langchain-ai/deepagents/actions/runs/25403894412) | [60%](https://github.com/langchain-ai/deepagents/actions/runs/25403894412) | | ollama:minimax-m2.7:cloud | [73%](https://github.com/langchain-ai/deepagents/actions/runs/24106499785) | [92%](https://github.com/langchain-ai/deepagents/actions/runs/24106499785) | [90%](https://github.com/langchain-ai/deepagents/actions/runs/24106499785) | [82%](https://github.com/langchain-ai/deepagents/actions/runs/24106499785) | [38%](https://github.com/langchain-ai/deepagents/actions/runs/23872647281) | [29%](https://github.com/langchain-ai/deepagents/actions/runs/24106499785) | [60%](https://github.com/langchain-ai/deepagents/actions/runs/24106499785) | | openrouter:deepseek/deepseek-v4-flash | [81%](https://github.com/langchain-ai/deepagents/actions/runs/25677815395) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25677815395)** | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25677815395) | **[90%](https://github.com/langchain-ai/deepagents/actions/runs/25677815395)** | — | [33%](https://github.com/langchain-ai/deepagents/actions/runs/25677815395) | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25677815395) | | openrouter:minimax/minimax-m2.7 | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | [92%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535)** | [89%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | — | [43%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | [60%](https://github.com/langchain-ai/deepagents/actions/runs/25455998535) | | openrouter:z-ai/glm-5.1 | **[89%](https://github.com/langchain-ai/deepagents/actions/runs/25387853856)** | [92%](https://github.com/langchain-ai/deepagents/actions/runs/25234719085) | **[100%](https://github.com/langchain-ai/deepagents/actions/runs/25234686782)** | [89%](https://github.com/langchain-ai/deepagents/actions/runs/25387853856) | — | [33%](https://github.com/langchain-ai/deepagents/actions/runs/25225620506) | [80%](https://github.com/langchain-ai/deepagents/actions/runs/25235579950) |

有关更多信息,请参阅 评估运行。

配置模型参数

以 provider:model 格式将模型字符串传给 create_deep_agent,或传入一个已配置的模型实例以获得完全控制。在底层,模型字符串通过 init_chat_model 解析。

要配置特定于模型的参数,请使用 init_chat_model,或直接实例化服务商模型类:

python
from langchain.chat_models import init_chat_model
from deepagents import create_deep_agent

model = init_chat_model(
    model="google_genai:gemini-3.6-flash",
    thinking_level="medium",  
)
agent = create_deep_agent(model=model)
python
from langchain_google_genai import ChatGoogleGenerativeAI
from deepagents import create_deep_agent

model = ChatGoogleGenerativeAI(
    model="gemini-3.1-pro-preview",
    thinking_level="medium",  
)
agent = create_deep_agent(model=model)

NOTE

可用参数因服务商而异。有关服务商特定的配置选项,请参阅 聊天模型集成 页面。

服务商配置文件

ProviderProfile 打包了一组初始化参数,当你创建深度智能体时提供 provider:model 字符串时,这些参数就会生效。它不会在你使用 init_chat_model 传入预配置模型时生效。

你可以在两个级别注册,而且两者可以共存:

  • 服务商级别:像 "openai" 这样的裸 provider 键会应用于来自 openai 服务商的每个模型。
  • 模型级别:像 "openai:gpt-5.4" 这样的 provider:model 键只应用于该特定模型,并会合并到任何匹配的服务商级别配置文件之上。
python
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.5 additionally gets a specific reasoning effort.
# Inherits temperature=0 from the provider-level profile above.
register_provider_profile(
    "openai:gpt-5.5",
    ProviderProfile(init_kwargs={"reasoning_effort": "medium"}),
)

有关完整字段列表、合并语义和插件打包,请参阅 配置文件。

TIP

若要在模型构建完成后塑造 智能体 的行为,请使用 harness 配置文件。

OpenAI 与 Responses API

当你将 openai:... 字符串作为模型传入时,Deep Agents 会使用内置的 OpenAI 服务商配置文件 来默认启用 Responses API。该路径支持 OpenAI 对话状态及相关功能;有关当前的 API 选项,请参阅 OpenAI 服务商 和 聊天模型 文档。

NOTE

内置的 OpenAI 服务商配置文件仅适用于模型字符串。要设置 use_responses_api、store 或 include 之类的 kwargs,请传入一个已配置的模型实例,或者在 Python 中通过 服务商配置文件 的 init_kwargs 来叠加它们。使用 init_chat_model(Python)或 initChatModel / ChatOpenAI(TypeScript)构建该实例。

要使用 Chat Completions 而不是 Responses API,请传入一个设置了 use_responses_api=False 的预初始化模型:

python
from langchain.chat_models import init_chat_model
from deepagents import create_deep_agent

model = init_chat_model("openai:gpt-5.5", use_responses_api=False)
agent = create_deep_agent(model=model)

要保留 Responses API 但禁用数据保留(store=False),同时仍接收加密的推理输出,请设置 include,使推理以加密内容的形式返回:

python
from langchain.chat_models import init_chat_model
from deepagents import create_deep_agent

model = init_chat_model(
    "openai:gpt-5.5",
    use_responses_api=True,
    store=False,
    include=["reasoning.encrypted_content"],
)
agent = create_deep_agent(model=model)

在运行时选择模型

如果你的应用允许用户选择模型(例如通过 UI 中的下拉菜单),请使用 中间件 在运行时替换模型,而无需重新构建智能体。

通过 运行时上下文 传入用户的模型选择,然后使用 wrap_model_call 中间件,借助 @wrap_model_call 装饰器在每次调用时覆盖模型:

python
from dataclasses import dataclass
from typing import Callable

from langchain.agents.middleware import ModelRequest, ModelResponse, wrap_model_call
from langchain.chat_models import init_chat_model
from deepagents import create_deep_agent

@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.6-flash",
    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.5"),
)

View example trace

打开本示例的一个公开 LangSmith 运行记录。

TIP

有关更多动态模型模式(例如基于对话复杂度或成本优化进行路由),请参阅 LangChain 智能体指南中的 动态模型。

了解更多


BytesRouter 是社区翻译站点,所有译文仅供参考,一切以官方英文原文为准。