模型能力

多智能体

查看 Markdown

实时多智能体研究使 Grok 能够编排多个实时协作的 AI 智能体,执行深入的多步骤研究任务。各智能体专注于研究的特定方面(搜索网络、分析数据、综合发现),共同给出全面且来源充分的答案。


概览

多智能体研究不止于单轮工具调用;它会协调一组专业智能体,以便:

  • 搜索和收集同时从多个来源收集信息

  • 分析并交叉验证不同领域的发现

  • 汇总带有引用和支持证据的全面答案

  • 迭代实时迭代研究,并根据中间发现优化结果


开始使用

要使用实时多智能体研究,请在 API 请求中将 grok-4.20-multi-agent 指定为模型名称。该模型专门针对编排多个协作完成研究任务的智能体进行了优化。

import os

from xai_sdk import Client
from xai_sdk.chat import user
from xai_sdk.tools import web_search, x_search

client = Client(api_key=os.getenv("XAI_API_KEY"))
chat = client.chat.create(
    model="grok-4.20-multi-agent",
    tools=[web_search(), x_search()],
    include=["verbose_streaming"],
)

chat.append(user("Research the latest breakthroughs in quantum computing and summarize the key findings."))

is_thinking = True
for response, chunk in chat.stream():
    if response.usage.reasoning_tokens and is_thinking:
        print(f"\rThinking... ({response.usage.reasoning_tokens} tokens)", end="", flush=True)
    if chunk.content and is_thinking:
        print("\n\nFinal Response:")
        is_thinking = False
    if chunk.content and not is_thinking:
        print(chunk.content, end="", flush=True)

print("\n\nUsage:")
print(response.usage)

多智能体的工作原理

向多智能体模型发送请求时,系统会启动多个智能体,围绕你的查询进行讨论和协作。每个智能体都会贡献自己的视角、推理和发现。指定的 主智能体负责汇总讨论并向你呈现最终答案。

支持的模型

  • grok-4.20-multi-agent

内置工具支持

xAI 提供一组可在请求中启用的内置工具,帮助处理最常见的使用场景,例如 web_searchx_searchcode_executioncollections_search。请查看此文档了解更多信息。

在请求中启用这些工具后,服务端会执行智能体循环,根据你的查询在服务端调用工具,直至生成最终答案。

输出行为

只有主智能体的 工具调用最终响应 会返回给用户。所有子智能体状态,包括中间推理、工具调用和输出,都会加密;只有当 xAI SDK 中的 use_encrypted_content设置为True时才包含在响应中。这样可以让默认响应保持简洁、聚焦,同时仍允许你为多轮对话保留完整的多智能体上下文。


配置

可以配置在一个请求中协作的智能体数量。可用的两种配置是4 个智能体16 个智能体。更多智能体可开展更深入、更全面的研究,但会增加 token 用量和延迟。

SDK / API参数4 个智能体16 个智能体
xAI SDKagent_count416
OpenAI SDKreasoning.effort"low""medium""high""xhigh"
Vercel AI SDKreasoningEffort"low""medium""high""xhigh"
REST APIreasoning.effort"low""medium""high""xhigh"

最适合:快速研究和范围明确的查询可使用 4 个智能体;深度研究和复杂的多方面主题可使用 16 个智能体。

4 个智能体配置

import os

from xai_sdk import Client
from xai_sdk.chat import user

client = Client(api_key=os.getenv("XAI_API_KEY"))
chat = client.chat.create(
    model="grok-4.20-multi-agent",
    agent_count=4,
)

chat.append(user("What are the key differences between TCP and UDP?"))
for response, chunk in chat.stream():
    if chunk.content:
        print(chunk.content, end="", flush=True)

16 个智能体配置

import os

from xai_sdk import Client
from xai_sdk.chat import user

client = Client(api_key=os.getenv("XAI_API_KEY"))
chat = client.chat.create(
    model="grok-4.20-multi-agent",
    agent_count=16,
)

chat.append(user("Analyze the design trade-offs in modern programming languages: compare Rust's ownership model, Go's simplicity philosophy, and Haskell's pure functional approach. Cover memory safety, concurrency, developer productivity, and ecosystem maturity."))
for response, chunk in chat.stream():
    if chunk.content:
        print(chunk.content, end="", flush=True)

常见模式

不使用内置工具

多智能体无需任何内置工具也能工作,各智能体完全依靠共同的知识和推理协作生成响应。

import os

from xai_sdk import Client
from xai_sdk.chat import user

client = Client(api_key=os.getenv("XAI_API_KEY"))
chat = client.chat.create(
    model="grok-4.20-multi-agent",
    include=["verbose_streaming"],
)

chat.append(user("Compare the major approaches to distributed consensus in computer science: Paxos, Raft, and Byzantine fault tolerance. Analyze the trade-offs in safety guarantees, performance, and implementation complexity."))

is_thinking = True
for response, chunk in chat.stream():
    if response.usage.reasoning_tokens and is_thinking:
        print(f"\rThinking... ({response.usage.reasoning_tokens} tokens)", end="", flush=True)
    if chunk.content and is_thinking:
        print("\n\nFinal Response:")
        is_thinking = False
    if chunk.content and not is_thinking:
        print(chunk.content, end="", flush=True)

print("\n\nUsage:")
print(response.usage)

多轮对话

与其他模型一样,多智能体研究可以使用previous_response_id进行多轮对话。你可以提出后续问题来完善或扩展之前的研究结果,智能体会使用先前上下文给出更有针对性的答案。

包含可复用函数和代码示例的完整多轮对话模式,请参阅串联对话


价格

无论是主智能体子智能体消耗的所有 token 都会计费,包括输入 token、输出 token 和推理 token。同样,任何智能体发出的所有服务器端工具调用,无论由主智能体还是子智能体发出,都会计入工具用量并相应收费。

由于多个智能体可能并行运行,且每个智能体都能独立调用工具,单个多智能体请求消耗的 token 和工具调用可能远多于标准的单智能体请求。你可以通过响应中的usageserver_side_tool_usage字段监控用量。

详细价格信息请参阅价格页面和工具价格页面。


多智能体提示指南

要充分发挥多智能体研究的能力,首先要合理组织请求。以下模式效果良好:

明确设置范围和深度

不要提出宽泛问题,应明确告诉智能体需要覆盖哪些维度:

Text

❌  "Tell me about electric vehicles."
✅  "Compare the top 3 EV manufacturers by battery technology, range, charging infrastructure, and 2025 sales projections."

要求结构化输出

当你要求有组织、结构清晰的响应时,多智能体研究表现尤为出色:

Text

✅  "Research the pros and cons of microservices vs monolithic architecture. Present your findings as a comparison table with categories: scalability, complexity, deployment, and team size requirements."

指定来源或视角

引导智能体使用你重视的证据类型:

Text

✅  "Analyze the environmental impact of large language model training, citing recent academic papers and industry reports from 2024-2025."

将复杂研究拆成对话

对于深度主题,先从宽泛问题开始,再通过 follow-up 逐步缩小范围,而不是将所有内容塞进一个 prompt:

Text

Turn 1: "What are the leading approaches to carbon capture technology?"
Turn 2: "Which of those has the best cost-per-ton economics today?"
Turn 3: "What are the main engineering challenges preventing that approach from scaling?"

在相关时提供上下文

如果研究基于已有知识或特定约束,请在 prompt 中提供这些上下文:

Text

✅  "I'm building a fintech app targeting Southeast Asian markets. Research the regulatory requirements for digital payments in Singapore, Indonesia, and the Philippines."

限制

  • 仅公开主智能体输出:仅返回主智能体的输出,包括工具调用和响应内容。子智能体状态会加密,并且仅在启用use_encrypted_content时包含,请参阅输出行为了解详情。

  • 不支持客户端或自定义工具:多智能体模型变体目前不支持客户端工具(function calling)和自定义工具。我们支持一组内置工具(例如web_searchx_search)和 remote MCP tools。请参阅我们的内置工具文档了解更多详情。

  • 不支持 Chat Completions API:多智能体模型支持 OpenAI Chat Completions API。请改用xAI SDKResponses API

  • max_tokens不受支持:当前多智能体模型变体不支持max_tokens参数。


最后更新:2026 年 7 月 2 日