Module 4Episode 49 min
The whole of module 4 as one video. Jump to any chapter, or read the lesson it comes from.
What it teaches, what that builds on, and what it opens up next.
You ask an agent to fix a failing test. Twenty minutes later, it's done. It ran the tests, read three files, changed one, and ran the tests again. Nobody told it to do any of those steps. So how does it work? Today, how a model asks for a tool, the loop that keeps it going, and the program around it all.
Leila asks, the model only writes text. How does the program know that some text is a request to do something, and not part of an answer? Omid asks back, if you wrote the program, how would you tell the difference? She says, I'd agree a special format with the model. And how would the model know which actions it may ask for? I'd tell it, in the request. A list. That's the whole mechanism. A list of actions in the request, and a fixed format for asking.
An action the model can ask for is called a tool. The program sends a list of them in every request. Each tool has a name, like get weather. A description in plain words. What it does, and when to use it. And the inputs it needs. Here, a city's name. When the model decides a tool would help, it doesn't answer in words. It writes a tool call. The tool's name, and its inputs, in a fixed format. Then it stops. The name says which tool. The input holds the values, shaped as the description asked. And there is no answer yet. The model has stopped, to wait.
Leila asks, should I take an umbrella in Tabriz today? One. The program sends the request. The system prompt, the tool list, and her question. Two. The model writes a tool call. Get weather, city Tabriz. And stops. Three. The program runs the real code behind the tool. Perhaps it asks a weather service on the internet. Four. The program adds the answer as a tool result. Light rain, nine degrees. And sends a new request. Five. The model reads the result, and writes its answer. Yes, take one. At no point did the model touch the internet. It wrote a request, and later read a result. Everything in the world was done by the program. This is also called function calling. So if a description is bad, the model might use the tool at the wrong time. Or not at all. The description is all the model knows about the tool. And every description is in every request. An agent with fifty tools carries fifty descriptions, all the time. Coding agents like Claude Code come with a handful of tools that cover almost everything. Read a file. Edit a file. Search files. Run a shell command. Fetch a web page. The shell command is the powerful one. Through it, the agent can use any program you can.
Three habits. One. Read the tool calls, not just the final answer. They show what the agent really did. Two. Expect tools to fail sometimes. The error comes back as a result, and a good agent tries again. Three. If you add tools, write their descriptions with care. What it does, when to use it, and when not to.
What turns one tool call into twenty? Something surprisingly small. The program sends the request to the model. If the reply asks for tools, it runs them, adds the results, and sends again. If the reply asks for no tools, that's the final answer. Show it, and stop. This is the agent loop. Notice who decides when to stop. Not the program. The model, by asking for no tools. In Python, the whole loop is about eight lines. Again and again, send everything to the model, and add its reply. If the reply has no tool calls, leave the loop. Otherwise, run the tools, add the results, and go round again. Leila is surprised. That's it? I thought an agent would be a huge, clever program. Omid says, the clever part is the model. The loop is just patient. It gives the model a chance to see what happened. Try something, look at the result, and change its mind. Like fixing a spreadsheet formula. Try, look, and try again. Every turn brings evidence.
Here is fix the failing test, as the turns it really is. Run the tests. Read the test file. Read the code. Edit the code. Run the tests again. A new error. Edit again. Run the tests. They pass. Final answer. Each turn is a full request, a bit longer than the last. And one turn can ask for several tools at once. The new error is what made it edit a second file. Nobody planned that. The results steer the next step.
The loop ends in one of three ways. The model decides it's done, and asks for no tools. The normal way. It hits a limit the program sets. A number of turns, a time, or a budget. Or you stop it. In Claude Code, pressing Escape stops it at once. And sometimes you should, because an agent can go round in circles. Only the model can notice it's stuck.
Three habits. One. Give the agent a way to check its work. Tests to run, a page to look at, a number to compare. Two. Step in when it goes round in circles. One sentence from you can save twenty wasted turns. Three. Keep tasks a sensible size. Split a huge task into pieces you can check.
Leila says, when I use Claude Code, I'm using Claude. The model. Omid asks, can the Claude app on your phone edit files in your project? No. Can the same model, inside Claude Code? Yes. So the difference isn't the model. It's everything around it. The tools, the system prompt, the loop. That program is called the harness. Like a horse's harness. The model is the strength. The harness points it at a job. The harness is everything in an agent except the model. It runs the loop. It holds the tools, and runs them. It writes the system prompt, and builds the context. It decides what's allowed. It talks to you. And it keeps records of your sessions. The model decides what to do. The harness decides what's allowed, carries it out, and remembers.
So the same model can be a chat assistant in one harness, and a coding agent in another. And one harness can run different models. When an agent disappoints you, sometimes the model isn't up to the task. But often the problem is in the harness. A missing tool. A cluttered context. A permission it didn't have. The harness also decides where the tools act. Claude Code usually runs on your own computer, so its tools work on your own files. Other agents run in the cloud, in a sandbox. A closed-off computer of their own. And programmers can build this kind of harness into their own programs, with the Claude Agent SDK.
Every module from here is about a part of the harness that you can shape. Giving an agent knowledge. Instruction files, memory, and skills. Keeping an agent in check. Permissions, hooks, and planning first. Many agents, many tools. Helper agents, and one standard plug for tools. And using agents well. Cost, safety, and checking the work.
Three habits. One. When an agent fails, ask which part failed. The model's judgement, or the harness. Two. Learn your harness, not just your model. Its commands, settings and files are where you have control. Three. Know where your agent runs. On your computer, it can touch your files. In a sandbox, only its own.
Let's put it together. A model uses a tool by writing a tool call. The program runs it, and sends back the result. The loop repeats that until the model asks for no tools. And the harness, everything but the model, is where you have control. Next time, giving an agent knowledge. Instruction files, memory, and skills. The lessons and quizzes for this course are free on knaph dot com. See you in the next episode.