From stub to real tools
In the last tutorial, the dispatch function was hard-coded. A real harness needs to add tools without rewriting the core loop. The solution is a tool registry: a dictionary that maps tool names to Python functions and their schemas.
Each tool is a function that takes arguments, does something, and returns a plain Python object. The harness does not care what the tool does; it only cares about the name, the arguments, and the result.
Key idea: tools are plugins. The loop stays the same even when you add new tools.
A tool registry
Below is a real ToolRegistry and three tools: read_file, write_file, and run_command. The harness can now read, write, and run code safely.
Memory and context
An LLM can only read a fixed number of tokens at once, called its context window. If a conversation gets too long, older messages must be dropped or summarized. A Memory class wraps that logic.
Watch memory shrink
Add messages until the memory reaches its limit. When it trims, older messages collapse into a summary so the model still has some idea what happened.
Check yourself
Why is it important that run_command has a timeout argument, and why should the harness not let the model run arbitrary shell commands?
Your answer:
Sample answer: A timeout prevents a command from hanging forever. The harness should limit which commands can run, or run them in an isolated sandbox, because an LLM could generate dangerous commands that delete files or leak data.
Quick quiz
1. What does the ToolRegistry do?
2. Why does memory need a max_messages limit?
3. What is a context window?
Keep learning
Tools and memory give the harness hands and a notebook. Next, wire them together into a coding agent that can read, edit, and test real code.
Part of the “How to Build an Agent Harness” series.