control-flow-recursive-helper.ts 555 B

1234567891011
  1. // A recursive helper: the SCC is a `loop` region in the trace, and the re-entrant call is a
  2. // `jump recur` back to it — on the CFG a back edge from the step before the recursive call
  3. // to the loop's entry.
  4. async function refine(draft: string, depth: number): Promise<string> {
  5. const review = await agent("critic").ask<string>(`review round ${depth}: ${draft}`);
  6. if (depth >= 3 || review.startsWith("ok")) return review;
  7. return refine(review, depth + 1);
  8. }
  9. const seed = await agent("writer").ask<string>("first draft");
  10. return refine(seed, 0);