phase-self-loop.ts 860 B

123456789101112131415161718192021222324
  1. // A refine-until-approved loop living entirely inside one phase. At the step level the
  2. // loop closes as a two-step cycle (plan → review forward, review → plan carry); quotiented
  3. // by a single phase the forward hop dissolves (intra-phase order is not drawn) and the
  4. // carry survives as the phase's SELF edge — the "the whole loop is in here" reading.
  5. interface Review {
  6. approved: boolean;
  7. /** What to change on the next round. */
  8. feedback: string;
  9. }
  10. phase("refine");
  11. const planner = agent("planner");
  12. const reviewer = agent("reviewer");
  13. let feedback = "none";
  14. let plan = "";
  15. for (let round = 0; round < 3; round++) {
  16. plan = await planner.ask<string>(`Plan the fixes. Feedback: ${feedback}`);
  17. const review = await reviewer.ask<Review>(`Critique:\n${plan}`);
  18. if (review.approved) return plan;
  19. feedback = review.feedback;
  20. }
  21. return plan;