← 全部示例
// 生产控制

固定并回放协调器计划

演示 planOnly + createPlanArtifact + runFromPlan:让协调器把目标分解一次、序列化成可 diff 的 JSON 产物,之后无需再调用协调器就能回放完全相同的任务图。任务 id、依赖、指派、描述与执行配置(memoryScope、重试设置)都被保留,所以回放的图与评审过的一致,而不是被 LLM 重新分解。

01 运行
OMA APIOpenMultiAgent
生产控制108 行

在仓库的克隆里运行这个文件:

terminal
npx tsx packages/core/examples/patterns/plan-replay.ts
前置条件
  • ANTHROPIC_API_KEY env var must be set.

OMA 与 provider 无关——这个示例按上面的 key 编写,但你也可以用 OpenAI、Gemini、Groq 等任意 provider 运行。 全部 provider →

展开完整同步源码 · 108 行

完整示例,从固定的 Framework commit 同步。

patterns/plan-replay.ts
/**
* Pin and Replay a Coordinator Plan
*
* Demonstrates `planOnly` + `createPlanArtifact` + `runFromPlan`: let the
* coordinator decompose a goal once, serialize that plan to a diffable JSON
* artifact, then replay the exact same task graph later WITHOUT invoking the
* coordinator again. Task ids, dependencies, assignees, descriptions, and
* execution config (memoryScope, retry settings) are preserved, so the replayed
* graph matches the reviewed one instead of being re-decomposed by an LLM.
*
* Scenario: a research + writing team. We decompose the goal once, persist the
* plan to disk, then rebuild it from the saved file and replay it.
*
* Run:
* npx tsx packages/core/examples/patterns/plan-replay.ts
*
* Prerequisites:
* ANTHROPIC_API_KEY env var must be set.
*/
 
import { writeFileSync, readFileSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { OpenMultiAgent } from '../../src/index.js'
import type { AgentConfig, PlanArtifact } from '../../src/types.js'
 
// ---------------------------------------------------------------------------
// Agents
// ---------------------------------------------------------------------------
 
const researcher: AgentConfig = {
name: 'researcher',
model: 'claude-sonnet-4-6',
systemPrompt: 'You research a topic and produce a concise, factual brief.',
maxTurns: 2,
}
 
const writer: AgentConfig = {
name: 'writer',
model: 'claude-sonnet-4-6',
systemPrompt: 'You turn a research brief into a short, well-structured guide.',
maxTurns: 2,
}
 
// ---------------------------------------------------------------------------
// Orchestrator + team
// ---------------------------------------------------------------------------
 
const orchestrator = new OpenMultiAgent({ defaultModel: 'claude-sonnet-4-6' })
 
const team = orchestrator.createTeam('research-team', {
name: 'research-team',
agents: [researcher, writer],
sharedMemory: true,
})
 
const goal =
'First research the benefits of TypeScript strict mode, then write a short adoption guide based on the findings.'
 
// ---------------------------------------------------------------------------
// Step 1 — decompose once (planOnly: coordinator runs, no agents execute yet)
// ---------------------------------------------------------------------------
 
console.log('Plan Replay Example')
console.log('='.repeat(60))
console.log('Step 1: decompose the goal (planOnly — coordinator only)')
 
const preview = await orchestrator.runTeam(team, goal, { planOnly: true })
 
// ---------------------------------------------------------------------------
// Step 2 — serialize to a diffable artifact and persist it
//
// `createPlanArtifact` returns a plain JSON-serializable object. Persist it
// however you like (here: a temp file; in practice, commit it to version
// control so the plan is reviewable and diffable).
// ---------------------------------------------------------------------------
 
const plan = orchestrator.createPlanArtifact(preview)
const planPath = join(tmpdir(), 'oma-plan.json')
writeFileSync(planPath, JSON.stringify(plan, null, 2))
 
console.log(`\nStep 2: saved a ${plan.tasks.length}-task plan to ${planPath}`)
for (const task of plan.tasks) {
const deps = task.dependsOn?.length ? ` (after: ${task.dependsOn.join(', ')})` : ''
console.log(` - ${task.title} -> ${task.assignee ?? 'auto-assigned'}${deps}`)
}
 
// ---------------------------------------------------------------------------
// Step 3 — replay the saved plan WITHOUT the coordinator
// ---------------------------------------------------------------------------
 
console.log('\nStep 3: replay from the saved artifact (no coordinator call)')
 
const saved = JSON.parse(readFileSync(planPath, 'utf8')) as PlanArtifact
const result = await orchestrator.runFromPlan(team, saved)
 
// ---------------------------------------------------------------------------
// Summary
// ---------------------------------------------------------------------------
 
console.log('\n' + '='.repeat(60))
console.log(`Replay success: ${result.success}`)
console.log(`Coordinator invoked: ${result.agentResults.has('coordinator')}`) // false (plan replayed as-is)
console.log(`Tokens — input: ${result.totalTokenUsage.input_tokens}, output: ${result.totalTokenUsage.output_tokens}`)
 
for (const task of result.tasks ?? []) {
console.log(` [${task.status}] ${task.title} (${task.assignee ?? 'unassigned'})`)
}
在 GitHub 查看 / 编辑
// 企业服务

要把它用到生产环境?

open-multi-agent 采用 MIT 许可、可自行免费运行。当你需要在期限内交付、集成,或获得支持时,元定义科技(YuanASI)提供商业交付与支持。

// 直接联系

把 Open Multi-Agent 用进真实业务

联系框架作者本人,帮你梳理 AI 落地目标、让 AI 真正与业务结合

可提供的工程服务
S-01

AI Agent 定制开发

业务梳理、Agent 设计、Prompt 评估、生产部署、私有化与持续支持。

S-02

多智能体系统集成

多 Agent 架构编排、RAG、CRM / ERP / API 对接、性能与稳定性调优。

S-03

企业 AI 咨询

AI 场景评估、技术选型、POC、ROI 估算与落地路线规划。