actor-names.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. // Actor naming: every legal shape under the "named actors must be unique" rule
  2. // (docs/execution-engine.md). This file must compile clean — it is the
  3. // false-positive guard for the duplicate-name diagnostic (9005), whose violations are
  4. // asserted in tests/actor-names.test.ts (the fixture suite here only typechecks).
  5. //
  6. // Distinct literal names, any number of anonymous actors, and dynamic names built in a
  7. // loop are all fine. Uniqueness of the dynamic ones is checked at run time by the
  8. // engine's createActor — a name only a running script knows cannot be checked here.
  9. const planner = agent("planner");
  10. const reviewer = agent("reviewer", { system: "You review." });
  11. const judge = agent("judge", { system: "You judge." });
  12. // Anonymous actors are legal in any number: the display label is the binding name, and
  13. // the price of staying anonymous is having no cache identity for a future amended re-run.
  14. const scratch = agent();
  15. const helper = agent();
  16. const plan = await planner.ask<string>("Draft a plan.");
  17. const review = await reviewer.ask<string>(`Review this plan:\n${plan}`);
  18. const verdict = await judge.ask<string>(`Ship it?\n${review}`);
  19. log(await scratch.ask<string>("Anything odd about this?"));
  20. log(await helper.ask<string>("Anything else?"));
  21. // Per-item workers: one site, many actors, names only the run knows.
  22. const items = ["a", "b", "c"];
  23. const notes: string[] = [];
  24. for (const item of items) {
  25. const worker = agent(`worker-${item}`, "You handle one item.");
  26. notes.push(await worker.ask<string>(`Handle ${item}.`));
  27. }
  28. return { verdict, notes };