Build your own coding agent · Chapter 13 of 20
A to-do list the agent keeps
By the end of this chapter Kaarigar keeps a to-do list for any task with several parts: the model writes it, your code keeps it and shows it back, nothing on it is lost, and the run cannot end quietly while an item is still open. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.
- Part: The loop that fixes
- 3 tasks
- Python
- In the all labs plan
The first 2 chapters of Build your own coding agent are free. This one comes with the all labs plan.
Why you need this
MD-109 is three small things on the receipt, from Sneha, numbered:
1. 'Luggage: 1 bags' should say 'Luggage: 1 bag'.
2. Big totals are not grouped: 'Total: ₹1197' should be 'Total: ₹1,197' (use `format_inr`).
3. Distance should always show one decimal: 'Distance: 3 km' should be 'Distance: 3.0 km'.
Run Kaarigar on it with a prompt that does not mention the tests, and it reads meterdown/receipt.py, makes two edits in one reply, and answers:
Fixed MD-109 (1 bag, not 1 bags; group the total) in meterdown/receipt.py.
Three requests, two parts. The third, one decimal of distance, never happened, and the answer does not say so. Riders still get "Distance: 3 km".
With the tests in the prompt, Kaarigar does find it: the test run fails on test_a_receipt_shows_one_decimal_of_distance, with expected: 'Distance: 3.0 km', and the failure reminds it. Rukhsana is blunt about that: "It found part 3 because I happen to have a test for that line. Sneha's next list will be five wording changes, and I do not have a test for each." A reminder that depends on a test somebody wrote for that exact line is luck, not machinery.
The model forgets for an ordinary reason: the numbered parts sit in the first user message, and every request after it piles more text on top: file contents, edits, results. Real models lose track of the middle of a long list the same way, and the more steps a task takes, the more likely it is. The lab model makes it exact: without a list, it does the first two parts of any task and forgets the rest.
What you build: 3 tasks
Each task has tests. You write the code in the lab's editor and press Check.
- Task 1
todos.py: a list Kaarigar keeps
Write a class Todos: items (a list of {"content", "status"} dicts, [] at the start), render() (one line per item, [x] CONTENT when its status is "completed", [ ] CONTENT otherwise; "(empty)" for no items), open() (the items not completed) and tool(): a Tool named todo_write with one required parameter, todos, an array of {content, status} objects (status one of "pending", "in_progress", "completed"). Its run takes the list the model sent as the new list, adds at the end every old item whose content the new list left out (with the status it had), and returns "The list now:", a new line, then render().
- Task 2
finish_guard.py: not done until the list is
Write finish_guard(todos, limit=2), which returns a function for the agent's on_done hook, (answer, run, ctx) -> dict or None. With no open items it returns None (the run ends). With open items, for the first limit times, it returns {"message": TEXT}: the line You still have open items on your list:, then one line per open item ("[ ] " and its content), then a last line asking the model to finish them or tick them. With items still open after limit reminders, it returns {"stop": "gave_up"}.
- Task 3 · interview question
Interview: parts.py, does the list pay for itself?
Run Kaarigar on MD-109 twice, each on a fresh checkout, with the system prompt NO_TESTS (given) and tools() without run_tests: "without a list", then "with a list" (the same tools plus Todos().tool()). After each run, a part is done when its test (issue("MD-109").tests) is not in run_tests(root).failing. Print one line per run:
LABEL: P of 3 parts, N steps
What you will learn
- Why agents keep a to-do list: the parts of a task, written down where the model sees them again.
- A list tool the model writes and your code keeps: todo_write, with the list shown back after every write.
- Nothing lost: an item the model leaves out of a new list is kept, still open.
- A finish guard: when the model says it is done with items open, the run goes on with a reminder.
- What the list costs in requests, and what it saves.
More in The loop that fixes
Build "A to-do list the agent keeps" yourself
MeterDown, a Pune app for auto-rickshaw fares, has eleven open issues. You build Kaarigar, an agent that fixes them without breaking tests, running risky commands or touching files outside the repository. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.
The first 2 chapters of Build your own coding agent are free. This one comes with the all labs plan.