The Tool Use Pattern: How AI Agents Interact with the Real World
The Tool Use pattern gives AI agents the ability to call APIs, query databases, run code, and take real-world actions.
The Tool Use pattern lets an AI agent decide when and how to call external tools (APIs, databases, code execution) based on the task at hand. It maps to the Adapter Pattern in software engineering.
Why tools matter
Without tools, an LLM is trapped in text-land. It can reason, but it can't act. It can suggest 'check the database' but can't actually query it. The Tool Use pattern breaks this wall. It gives the agent hands — the ability to search the web, call APIs, query databases, execute code, send emails, and interact with any external system.
How tool calling works
Modern LLMs (GPT-4, Claude, Gemini) have native tool-calling support. You define tools as function signatures with descriptions. The LLM sees the available tools, decides which one to use, and returns a structured tool call with arguments. Your code executes the function and feeds the result back to the LLM. The LLM then decides: do I need another tool, or can I answer now?
tools = [
{
"name": "get_weather",
"description": "Get current weather for a city",
"parameters": {
"city": {"type": "string", "required": True}
}
}
]
# LLM sees the tools and decides to call one
response = llm.call(
"What's the weather in Tokyo?",
tools=tools
)
# → { "tool": "get_weather", "args": { "city": "Tokyo" } }
# Execute the tool, feed result back
weather_data = get_weather("Tokyo")
final = llm.call(f"Weather data: {weather_data}. Answer the user.")The SWE parallel: Adapter Pattern
Tool Use maps to the Adapter Pattern. Each tool wraps an external system behind a standard interface that the agent understands. The agent doesn't know how the GitHub API works — it knows there's a 'create_issue' tool that takes a title and body. The tool adapter handles the translation. Same principle as wrapping a third-party library behind a clean interface in your codebase.
Best practices
Write clear tool descriptions — the LLM uses them to decide when to call each tool. Keep tool count manageable (under 20 for best results). Always validate tool arguments before execution. Handle tool failures gracefully — the agent should be able to retry or use an alternative. Log every tool call for debugging and auditing.
Tool Use is what turns an LLM into an agent. Define tools as functions, let the LLM decide when to call them, and feed results back. It maps to the Adapter Pattern in software engineering.
This post covers the basics. The full curriculum page for Tool Use includes the SWE mapping, code examples, production notes, and an interactive building exercise.
Tool Use → Adapter / Proxy Pattern