模型能力
Multi Agent
Realtime Multi-agent Research 使 Grok 能够编排多个实时协作的 AI Agent,执行深入的多步骤研究任务。各 Agent 专注于研究的特定方面(搜索网页、分析数据、汇总发现),共同给出全面且来源充分的答案。
概览
Multi-agent research 不仅是单轮工具调用,它会协调一组专业 Agent,这些 Agent 可以:
搜索和收集来自多个来源的信息
分析并交叉验证不同领域的研究发现
汇总带有引用和支持证据的全面答案
迭代实时研究,并根据中间发现优化结果
开始使用
要使用 Realtime Multi-agent Research,请在 API 请求中将grok-4.20-multi-agent指定为模型名称。该模型专门针对编排多个协作完成研究任务的 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)Multi-agent 的工作原理
向 multi-agent 模型发送请求时,系统会启动多个 Agent,围绕你的 query 进行讨论和协作。每个 Agent 都会贡献自己的视角、推理和发现。指定的leader Agent负责汇总讨论并向你呈现最终答案。
支持的模型
grok-4.20-multi-agent
内置工具支持
xAI 提供一组可在请求中启用的内置工具,帮助处理最常见的使用场景,例如web_search、x_search、code_execution、collections_search。请查看此文档了解更多信息。
在请求中启用这些工具后,服务器会执行 Agent loop,根据你的 query 在服务器端调用工具,直至生成最终答案。
输出行为
只有 leader Agent 的tool calls和最终响应会返回给用户。所有 sub-agent 状态,包括中间推理、tool calls 和输出,都会加密;只有当 xAI SDK 中的use_encrypted_content设置为True时才包含在响应中。这样可以让默认响应保持简洁、聚焦,同时仍允许你为多轮对话保存完整 multi-agent context。
配置
可以配置在一个请求中协作的 Agent 数量。可用的两种配置是4 个 Agent和16 个 Agent。更多 Agent 可以开展更深入、更全面的研究,但会增加 token 用量和延迟。
| SDK / API | 参数 | 4 个 Agent | 16 个 Agent |
|---|---|---|---|
| xAI SDK | agent_count | 4 | 16 |
| OpenAI SDK | reasoning.effort | "low"或"medium" | "high"或"xhigh" |
| Vercel AI SDK | reasoningEffort | "low"或"medium" | "high"或"xhigh" |
| REST API | reasoning.effort | "low"或"medium" | "high"或"xhigh" |
最适合:快速研究和范围明确的 query 使用 4 个 Agent;深度研究和复杂的多方面主题使用 16 个 Agent。
4-Agent 配置
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-Agent 配置
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)常见模式
不使用内置工具
Multi-agent 无需任何内置工具也能工作,Agent 完全依靠共同的知识和推理协作生成响应。
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)多轮对话
与其他模型一样,multi-agent research 可以使用previous_response_id进行多轮对话。你可以提出后续问题来完善或扩展之前的研究结果,Agent 会使用先前 context 给出更有针对性的答案。
包含可复用函数和代码示例的完整多轮对话模式,请参阅串联对话。
价格
无论是leader Agent和sub-agents消耗的所有 tokens 都会计费,包括 input tokens、output tokens 和 reasoning tokens。同样,任何 Agent 发出的所有服务器端 tool calls,无论由 leader 还是 sub-agent 发出,都会计入工具用量并相应收费。
由于多个 Agent 可能并行运行,并且每个 Agent 都可以独立调用工具,单个 multi-agent 请求消耗的 tokens 和 tool calls 可能远多于标准的 single-agent 请求。你可以通过响应中的usage和server_side_tool_usagefields 监控用量。
Prompting 指南
要充分发挥 multi-agent research 的能力,首先要合理组织请求。以下模式效果良好:
明确设置范围和深度
不要提出宽泛问题,应明确告诉 Agent 需要覆盖哪些维度:
❌ "Tell me about electric vehicles."
✅ "Compare the top 3 EV manufacturers by battery technology, range, charging infrastructure, and 2025 sales projections."要求结构化输出
当你要求有组织、结构清晰的响应时,multi-agent research 表现尤为出色:
✅ "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."指定来源或视角
引导 Agent 使用你重视的证据类型:
✅ "Analyze the environmental impact of large language model training, citing recent academic papers and industry reports from 2024-2025."将复杂研究拆成对话
对于深度主题,先从宽泛问题开始,再通过 follow-up 逐步缩小范围,而不是将所有内容塞进一个 prompt:
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?"在相关时提供 context
如果研究基于已有知识或特定约束,请在 prompt 中提供这些 context:
✅ "I'm building a fintech app targeting Southeast Asian markets. Research the regulatory requirements for digital payments in Singapore, Indonesia, and the Philippines."限制
只公开 leader Agent 输出:只返回 leader Agent 的输出,包括 tool calls 和响应内容。Sub-agent 状态会加密,并且仅在启用
use_encrypted_content时包含,请参阅输出行为了解详情。不支持客户端或自定义工具:Multi-agent 模型变体目前不支持客户端工具(function calling)和自定义工具。我们支持一组内置工具(例如
web_search、x_search)和 remote MCP tools。请参阅我们的内置工具文档了解更多详情。不支持 Chat Completions API:Multi-agent 模型不支持 OpenAI Chat Completions API。请改用xAI SDK或Responses API。
max_tokens不受支持:当前 multi-agent 模型变体不支持max_tokens参数。