handoff-family-self-carry.ts 1.1 KB

12345678910111213141516171819202122232425
  1. // 交接图:fan-out 里的 ask 带 carry 自环(`Promise.all(map(async …))` 的包装对象让它按串行
  2. // 记账),展开成成员卡后**不得**变成成员两两互连的回边——家族成员之间没有交接。
  3. interface Finding { id: string; title: string; }
  4. interface ResearchResult { findings: Finding[]; }
  5. interface Report { markdown: string; }
  6. const ANGLES = [
  7. { key: "history", name: "research-history", brief: "history" },
  8. { key: "frontier", name: "research-frontier", brief: "frontier" },
  9. { key: "safety", name: "research-safety", brief: "safety" },
  10. { key: "critique", name: "research-critique", brief: "critique" },
  11. ];
  12. phase("并行调研");
  13. const wrapped = await Promise.all(
  14. ANGLES.map(async (a) => ({
  15. key: a.key,
  16. result: await agent(a.name, { system: "researcher" }).ask<ResearchResult>(`调研 ${a.brief}`),
  17. })),
  18. );
  19. const corpus = wrapped.map((w) => `${w.key}: ${JSON.stringify(w.result.findings)}`).join("\n");
  20. phase("撰写终稿");
  21. const out = await agent("writer", { system: "writer" }).ask<Report>(`合成 ${corpus}`);
  22. return out.markdown;