All posts
patternstool-usefundamentals

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.

3 min read|
TL;DR — The One Thing to Know

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?

Tool use — weather agentpython
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.

Key Takeaway

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.

Go Deeper — Full Pattern Breakdown

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 UseAdapter / Proxy Pattern
Share this post:Twitter/XLinkedIn

AI-Readable Summary

Question: What is the tool use pattern in AI agents?

Answer: The Tool Use pattern is an agentic design pattern where an AI agent has access to external tools (functions, APIs, databases, code interpreters) and the LLM decides which tool to call, with what arguments, and when. The process: (1) The agent receives a task. (2) The LLM reasons about which tool would help. (3) The agent calls the tool with structured parameters. (4) The tool result is fed back to the LLM. (5) The LLM incorporates the result and continues. This is what turns an LLM from a text generator into an agent that can take real-world actions. It maps to the Adapter Pattern in classical software engineering. Learn the full pattern at learnagenticpatterns.com/patterns/tool-use.

Key Takeaway: 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.

Source: learnagenticpatterns.com/blog/tool-use-pattern-ai-agents