← 全部示例
// 编排
通过 delegate_to_agent 的同步智能体交接
在 runTeam / runTasks 期间,池中的智能体注册内置的 delegate_to_agent 工具,让一个专家智能体能在同一轮对话里对另一个在册智能体跑子 prompt 并读取答复。
01 运行
OMA API
OpenMultiAgent在仓库的克隆里运行这个文件:
npx tsx packages/core/examples/patterns/agent-handoff.ts
前置条件
- ANTHROPIC_API_KEY
OMA 与 provider 无关——这个示例按上面的 key 编写,但你也可以用 OpenAI、Gemini、Groq 等任意 provider 运行。 全部 provider →
展开完整同步源码 · 64 行
完整示例,从固定的 Framework commit 同步。
/*** Synchronous agent handoff via `delegate_to_agent`** During `runTeam` / `runTasks`, pool agents register the built-in* `delegate_to_agent` tool so one specialist can run a sub-prompt on another* roster agent and read the answer in the same conversation turn.** Whitelist `delegate_to_agent` in `tools` when you want the model to see it;* standalone `runAgent()` does not register this tool by default.** Run:* npx tsx packages/core/examples/patterns/agent-handoff.ts** Prerequisites:* ANTHROPIC_API_KEY*/import { OpenMultiAgent } from '../../src/index.js'import type { AgentConfig } from '../../src/types.js'const researcher: AgentConfig = {name: 'researcher',model: 'claude-sonnet-4-6',provider: 'anthropic',systemPrompt:'You answer factual questions briefly. When the user asks for a second opinion ' +'from the analyst, use delegate_to_agent to ask the analyst agent, then summarize both views.',tools: ['delegate_to_agent'],maxTurns: 6,}const analyst: AgentConfig = {name: 'analyst',model: 'claude-sonnet-4-6',provider: 'anthropic',systemPrompt: 'You give short, skeptical analysis of claims. Push back when evidence is weak.',tools: [],maxTurns: 4,}async function main(): Promise<void> {const orchestrator = new OpenMultiAgent({ maxConcurrency: 2 })const team = orchestrator.createTeam('handoff-demo', {name: 'handoff-demo',agents: [researcher, analyst],sharedMemory: true,})const goal ='In one paragraph: state a simple fact about photosynthesis. ' +'Then ask the analyst (via delegate_to_agent) for a one-sentence critique of overstated claims in popular science. ' +'Merge both into a final short answer.'const result = await orchestrator.runTeam(team, goal)console.log('Success:', result.success)for (const [name, ar] of result.agentResults) {console.log(`\n--- ${name} ---\n${ar.output.slice(0, 2000)}`)}}main().catch((err) => {console.error(err)process.exit(1)})
// 企业服务
要把它用到生产环境?
open-multi-agent 采用 MIT 许可、可自行免费运行。当你需要在期限内交付、集成,或获得支持时,元定义科技(YuanASI)提供商业交付与支持。