async-promise-double-await-mutate.ts 531 B

123456789
  1. // Double await of one Node: both awaits settle to the SAME object at runtime, so a
  2. // mutation between them (push of the critic's output) is visible via the second await.
  3. // Expected: ask#1 -> ask#3 data; ask#2 -> ask#3 data; ask#3 -> sink.
  4. const plan = agent("planner").ask<{ steps: string[] }>("plan the work");
  5. const first = await plan;
  6. const extra = await agent("critic").ask<string>("one more step");
  7. first.steps.push(extra);
  8. const second = await plan;
  9. return agent("executor").ask<string>(`do: ${second.steps.join("; ")}`);