Project
ReAct Agent Harness
A ReAct agent harness I built from scratch in Python for CMU 11-768, AI Agents. One loop runs two agents: a coding agent that fixes software issues in a sandbox, and a chess agent that searches with code before it moves.
- Loop Build the prompt, get an action, run its tool calls, add what came back, repeat.
- Fix As a coding agent it works in a terminal in a Modal sandbox and hands in its fix as a patch.
- Compact On a longer issue the model rewrites old turns as working memory, so the context stays small.
- Play As a chess agent it tries moves in code first, then plays one on the real board.
The loop
Both agents share one ReAct loop that knows nothing about code or chess. Each step it builds the messages for the model: the standing instructions, the task, and every earlier action with what it returned. Then it asks for the next action, runs each tool call, and links every result back to the call that asked for it.
A model can send broken JSON or ask for a tool that does not exist. Those come back to it as results it can read and recover from, so a bad call does not end the run. A step limit does.
Skills
A skill is a folder with a SKILL.md in it. The harness reads each skill’s name and description into a short catalog in the prompt, and the full instructions only load when the model asks for that skill. The coding agent has one that teaches it how to hand in its work as a patch.
Context compaction
Long runs fill the context window and cost more with every step. When the context passes a token threshold, the model is asked to rewrite the older part of the transcript as short working memory: the goal, the constraints, the files and commands, what was edited, what failed, and what comes next.
The original instructions and the task stay word for word, and so does the latest complete action with its results. The coding agent used this to patch a SWE-bench issue in Django (django__django-15368, where bulk_update() did not work with plain F() expressions).
The chess agent
The chess agent runs on the same loop with three tools:
play_moveplays one move on the live board, and the opponent answerssimulate_movetries a move from any position without touching the live gamerun_pythonruns code the model wrote, with the other two available as ordinary functions
That last one is programmatic tool calling. The model writes a small search that simulates its candidate moves and the replies to them, then plays the one it picked. The code it writes runs in the sandbox, never in the agent’s own process.
