Tool calling
A model calls tools by asking your code to run them
The model returns a tool call; your app runs it and returns the result.
A model on its own can only write text. Tools let it reach live data and take actions. The app sends the question with descriptions of the tools available. The model decides a tool would help, and replies with a structured call. The app runs the real function. It gets the result. And sends it back. Now the model can answer. The model asked; your code acted.
Tool calling · Going deeper
What a tool definition looks like
A name, a description the model reads, and an input schema.
The agent loop
An agent loops: reason, act, observe, until the goal is met
Reason, act with a tool, observe the result, repeat, within a step limit.
Give a model tools and a goal, and let it repeat tool calls, and you have an agent. It works out what it needs. It searches flights. Reads the result. Wonders about the rules. Checks the policy. Learns rebooking is free. Books the seat. And reports back. No one scripted those steps; the model chose them.
The agent loop · Going deeper
Managed agent services
Services run the loop and add memory, tool access and tracing.
Model Context Protocol
MCP lets any AI app use any tool through one standard
MCP turns 5 × 8 = 40 integrations into 5 + 8 = 13.
Without a standard, every AI app needs custom code for every tool. Five apps and eight tools means forty integrations to build and maintain. The Model Context Protocol fixes the plug. Each app implements an MCP client once. Each tool exposes an MCP server once. That is thirteen pieces of work, and any app can use any tool.
Model Context Protocol · Going deeper
Hosts, clients, servers and transports
Host, client, server; tools, resources, prompts; stdio or Streamable HTTP.
Memory
The context fills with every step; agents summarise and store
Short-term memory is the context; compaction summarises it; long-term memory is a store.
An agent’s working memory is its context window. Every tool result goes in. Here each step adds nine thousand tokens, and without help the context passes its limit at step 14, long before cost and delay stop being a problem. With compaction, when it reaches three quarters full, the old turns are replaced by a short summary, and the agent carries on. Facts worth keeping between sessions go to a long-term store, and are retrieved when needed.
Workflows and agents
Fix the steps when you can; use an agent when you must
Workflow: steps in code. Agent: the model picks the path.
There are two ways to build with models. A workflow fixes the steps in code, with a model call inside some of them: extract, check, draft. It does the same thing every time, so it is easy to test. An agent lets the model choose the next step. That handles the unexpected, but it is slower, costlier and harder to predict. Start with a workflow; reach for an agent when the path truly depends on what is found.
Why long chains fail
Small error rates compound over many steps
95% per step: 59.9% after 10 steps, 35.8% after 20.
If each step goes right ninety five percent of the time, the whole task needs every step to go right. After ten steps that is 59.9 percent. After twenty, 35.8 percent. Raise each step to ninety nine percent and twenty steps still succeed 81.8 percent of the time. So keep tasks short, make each step reliable, and check progress as you go.
Checks and retries · Going deeper
A check after each step buys back most of the lost reliability
Verify each step in code where you can, and retry once on a caught failure.
Keeping agents safe
Least privilege and a person’s approval for risky actions
Least privilege, approval for irreversible actions, limits and logs.
An agent can do whatever its tools allow, so put gates in the path. The agent proposes a refund. Is this tool allowed for this role, and is this the user’s own order? The amount is over the limit, so it is high risk. A person approves it. Only then does it run, with credentials scoped to this task, and the call is logged.
Lesson complete
You finished “Agents and tools”
Nicely done.