Sub topic 16
Tool integration standards and agent frameworks
This chapter assumes you can write the tool registry and agent loop from earlier chapters, and that you can read JSON schemas. It covers what changes when many tools come from many places, and when a framework is worth using.
The problem standards solve
Your TOOLS dictionary works for a handful of functions you wrote yourself. It gets awkward when you want to reuse tools written by others, such as a file search, a calendar, or a database client. Each tool needs a name, a description, an argument schema, and a way to be called. Without a shared format, you write glue code for every tool and every model provider.
A tool integration standard fixes this by defining one message format for listing tools and calling them. The best-known example is the Model Context Protocol (MCP). In MCP, a tool server advertises its tools, and a client inside your agent lists them and forwards calls.
What a standard gives you
- Discovery. The client asks a server "what tools do you offer?" and gets names, descriptions, and schemas. You do not hard-code them.
- A uniform call. Every tool is invoked with a name and a JSON arguments object, the same shape your
run_toolalready uses. - Reuse. One server can serve many agents and many models.
Your registry from earlier can act as a minimal version of this. The sketch below makes it discoverable:
import json
def get_weather(city: str) -> str:
return json.dumps({"city": city, "temp_c": 18})
TOOLS = {
"get_weather": {
"function": get_weather,
"description": "Get current temperature for a city.",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}
}
def list_tools() -> list:
return [
{"name": n, "description": t["description"], "parameters": t["parameters"]}
for n, t in TOOLS.items()
]
def run_tool(name: str, arguments: dict) -> str:
if name not in TOOLS:
return json.dumps({"error": f"unknown tool: {name}"})
try:
return TOOLS[name]["function"](**arguments)
except Exception as exc:
return json.dumps({"error": str(exc)})
print(json.dumps(list_tools(), indent=2))
print(run_tool("get_weather", {"city": "Oslo"}))A real protocol adds transport (local process or network), authentication, and versioning on top of this idea.
What a framework gives you
An agent framework packages the loop, the tool registry, history handling, tracing, and often retries. You describe tools and goals, and it runs the loop.
| Concern | Hand-written loop | Framework |
|---|---|---|
| Control over each step | Full | Varies, often hidden behind abstractions |
| Time to first working agent | Longer | Shorter |
| Debugging | Read your own code | Read framework code and docs |
| Provider switching | You write adapters | Often built in |
| Upgrades | Yours to manage | Can break your code |
Common errors
- Trusting third-party tools. A tool server's descriptions and outputs are data from outside your control. Apply the same permission checks and input validation you use for your own tools.
- Too many tools. Connecting several servers can put dozens of tool descriptions into the context window. This costs tokens and makes the model choose worse. Expose only what the task needs.
- Adopting a framework before understanding the loop. When an agent misbehaves, you need to know what the loop is doing.
Exercise
Your agent connects to three tool servers and starts picking the wrong tools more often. Name the likely cause and one fix.
Show answer
The tool descriptions from all servers fill the context and give the model too many similar choices. Fix it by exposing only the tools the task needs, or by sharpening tool names and descriptions so they are distinct.