← Table of Contents · Page 113 of 868

STATE AND CONTROL FLOW

Part 6 of 9

EXAMPLES Example 1: State that prevents a repeat mistake. A coding agent is asked to fix a typo in every file of a project. The harness keeps a state field called files_already_edited. Before the agent edits a file, the harness checks the list. When the agent tries to edit config.py a second time, the harness replies "You already edited config.py in step 4. Do you want to change it again?" Without that state, the agent might apply the same edit twice and break the file. Example 2: A checkpoint saves hours of work. A data migration job copies records between two systems in 30 steps. A checkpoint is written after step 10, then 20. At step 25 the machine loses power. An engineer restarts the job. The harness reads the most recent checkpoint, which says "completed through step 20," and resumes from step 21. If the engineer had only the step 10 checkpoint, the job would resume at step 11. In both cases the saved progress cut the lost work from 25 steps to at most 15. Example 3: Human-in-the-loop pause before a mass email. A marketing agent has prepared an email for 10,000 customers. The send tool is classified as risky, so the harness pauses before calling it. It saves the state and shows a reviewer: the subject line, a sample of the body, the recipient count (10,000), and the list segment chosen. The reviewer notices that the discount code in the email expired last week and clicks "reject" with a note. The agent receives the note, fixes the code, and the reviewer approves a second time. Only then does the harness actually fire the send tool. If nobody had responded within, say, 24 hours, the safe fallback is to cancel the send and alert the campaign owner. Example 4: Rollback of three bad edits. An agent edits three files, each time making a mistake because it misread a function name. Before starting the edits, the harness had saved a checkpoint that included a Git commit marker. The harness runs a revert to that commit, and all three files return to their earlier content at once. The state container is also reset to the checkpoint, so the agent's counters and notes match the restored files. The agent starts again with a note in its history saying "your previous three edits were reverted because the function name was wrong."
Advertisement
Read Aloud:
0:00 / 0:00