编排一个动态多智能体团队,其中主导智能体(opus)规划并将任务委托给专门的工作智能体(sonnet),后者进行双向通信。
Orchestrate a dynamic team of agents: one Orchestrator (opus) plans + delegates + synthesizes; multiple Worker agents (sonnet) execute specialized subtasks and communicate bidirectionally.
text
User
└─► Orchestrator (opus)
├─ plans team composition dynamically
├─ spawns Worker A (sonnet) ──┐
├─ spawns Worker B (sonnet) │ bidirectional
├─ spawns Worker C (sonnet) ◄─┘ via sessions_send
└─ aggregates → final report to user
Analyze the task and define 2–4 worker roles. Each role needs:
researcher, coder, reviewer)See references/role-patterns.md for common role combinations per scenario.
Spawn each worker as a persistent sub-agent session. Always set streamTo: "parent" so the user sees real-time output in their chat window:
python
# Pseudocode — use sessions_spawn tool
sessions_spawn(
task="You are the [ROLE] agent. [SPECIFIC TASK].
When you need input from another agent, send a message to session [SESSION_KEY].
Report your final result clearly structured.",
runtime="subagent",
mode="session", # persistent — can receive follow-up messages
model="sonnet", # worker uses sonnet
label="worker-[role]",
streamTo="parent" # stream output to user's chat in real time
)
Spawn all independent workers in parallel (single tool call block). Only spawn sequentially when a worker strictly depends on another's output.
Workers can message each other via sessions_send. The orchestrator:
subagents(action=list) — check on-demand, not in a loopsubagents(action=steer, target=<label>, message=<redirect>)Direct worker-to-worker message pattern:
text
Worker A finishes partial result
→ sessions_send(sessionKey=worker-B-key, message="Here's my output: ...")
Worker B incorporates it, finishes
→ sessions_send(sessionKey=orchestrator-key, message="Done: ...")
After each worker completes, send a status update to the user before moving on:
text
"[worker-researcher] 完成 ✅ — 找到 12 条相关数据,传给 worker-analyst"
"[worker-analyst] 处理中... 等待 worker-researcher 结果"
"[worker-reviewer] 完成 ✅ — 发现 3 个风险点"
This gives the user full visibility into the team's progress without needing to check logs manually.
Once all workers report back, the orchestrator:
RoleModelRationaleOrchestratorCurrent session model (Jarvis / Friday / Jupiter)Complex planning + synthesisWorkerssonnetCost-efficient execution
Orchestrator identities:
Override worker model when a subtask needs deeper reasoning: pass model="anthropic/claude-opus-4-6" to that specific spawn.
See references/role-patterns.md for ready-made role sets:
reader + security-reviewer + refactor-plannerdata-analyst + sentiment-analyst + risk-assessortechnical-analyst + fundamental-analyst + macro-watchersubagents(action=list) only when checking status on-demandsubagents(action=kill, target=<label>)