emission-graph-fanout-map-wrap-aggregate.ts 1.2 KB

1234567891011121314151617181920212223
  1. // Root cause 8, integration: a two-stage fan-out where the second stage's per-item map
  2. // wraps the awaited critic ask in a SHORTHAND object literal (`{ idea, critique }`), a judge
  3. // aggregates the wrapped entries, and the script returns `{ entries, verdict }` (both
  4. // shorthands). The wrap dropped every critic label, so the critic ask reached neither the
  5. // join nor the judge, and the returned `entries` never reached the sink. With the fix the
  6. // wrapped labels survive both the join relay and the return.
  7. // Expected: critic ask#2 -> join#2 and ask#2 -> ask#3(judge); judge ask#3 -> sink;
  8. // join#2 -> sink (the returned entries carry the aggregated critiques).
  9. const personas = ["dreamer", "engineer"];
  10. const ideas = await Promise.all(
  11. personas.map((p) => agent(`inventor-${p}`).ask<string>(`pitch for ${p}`)),
  12. );
  13. const entries = await Promise.all(
  14. ideas.map(async (idea, i) => {
  15. const critic = agent(`critic-${i}`);
  16. const critique = await critic.ask<string>(`critique ${idea}`);
  17. return { idea, critique };
  18. }),
  19. );
  20. const verdict = await agent("judge").ask<string>(
  21. `crown a winner: ${entries.map((e) => e.critique).join(", ")}`,
  22. );
  23. return { entries, verdict };