Loading patterns…
Tool Use
External tool integration and function calling patterns
In 30 seconds
- What
- Connects AI systems to external tools, APIs, databases, and services so agents can execute actions beyond text generation like calculations, data retrieval, file operations, and system interactions.
- When to use
- Tasks needing real-time data unavailable in training, precise calculations beyond text, API or database interactions, or file and system operations.
- Watch out
- Insufficient error handling when tools fail or become unavailable can cascade into system failures and broken workflows.
Ask the AI expert about these patterns
Opens the assistant with your question prefilled. You review it before sending.
Overview
Tool use patterns enable AI systems to extend their capabilities by integrating with external tools, APIs, databases, and services. These patterns allow AI agents to perform actions beyond text generation, such as making calculations, accessing real-time data, executing code, manipulating files, or interacting with external systems, dramatically expanding the scope of tasks they can accomplish autonomously.
Practical Applications & Use Cases
Data Analysis
Integrating with analytical tools and databases to perform complex data processing and visualization.
Code Execution
Running and testing code in various programming languages to verify functionality and provide results.
API Integration
Connecting with external services for weather data, financial information, or third-party functionality.
File Management
Reading, writing, and manipulating files and documents across different formats and storage systems.
Mathematical Computation
Using specialized computational tools for complex mathematical operations and scientific calculations.
Web Automation
Interacting with web services, scraping data, or automating browser-based tasks.
System Administration
Performing system operations, monitoring resources, and managing infrastructure.
Content Creation
Utilizing specialized tools for image generation, video editing, or document formatting.
Why This Matters
Tool use patterns are fundamental for creating practical AI agents that can interact with real-world systems and perform concrete actions. They bridge the gap between AI reasoning capabilities and practical utility, enabling agents to access current information, perform precise calculations, and execute tasks that require interaction with external systems. This capability transforms AI from a text generation tool into a versatile automation platform.
Implementation Guide
When to Use
- Tasks requiring real-time or current information not available in training data
- Applications needing precise calculations or data analysis beyond text generation
- Systems that must interact with external APIs or databases
- Workflows requiring file manipulation or system operations
- Scenarios where verification or execution of generated code is needed
- Applications requiring integration with existing business systems
Best Practices
- Design robust error handling for tool failures and network issues
- Implement proper authentication and security measures for tool access
- Use tool abstraction layers to simplify integration and maintenance
- Validate tool inputs and sanitize outputs to prevent security issues
- Implement rate limiting and resource management for tool usage
- Provide clear documentation and examples for each available tool
- Monitor tool usage and performance for optimization opportunities
Common Pitfalls
- Insufficient error handling leading to system failures when tools are unavailable
- Security vulnerabilities from improper input validation or excessive permissions
- Over-reliance on tools for tasks that could be handled with AI capabilities alone
- Poor tool selection leading to inefficient or incorrect task execution
- Not considering the latency and cost implications of external tool usage
- Inadequate monitoring and logging of tool interactions for debugging
Available Techniques
Function Calling
Structured interface for AI to invoke external functions and APIs
Code Execution
Safely execute LLM-generated code in isolated environments for calculations and data processing
Model Context Protocol(MCP)
Standardized protocol for sharing context and capabilities between AI models and tools
Control Plane as a Tool(CPT)
Exposes a single unified tool interface to the agent while an internal control plane routes each request to the right tool, service, or model behind it. The agent prompt stays stable as the tool catalog evolves, and authentication, policy, rate limiting, and observability are enforced in one place.
Computer Use(CU)
Agents operate graphical user interfaces (desktop, browser, or mobile) the way a person does, by reading screenshots and issuing mouse and keyboard actions instead of calling APIs. The core challenge is GUI grounding: mapping an intent to exact pixel coordinates on the screen. The agent runs a loop of screenshot, reason, act, and observe until the task is complete.
Agent Skills(AS)
Capabilities packaged as self-contained folders. Each skill is a SKILL.md file with YAML frontmatter (name and description) plus optional scripts and resources. Agents discover skills by their metadata and load them through three levels of progressive disclosure: read name and description to judge relevance, load the full SKILL.md once activated, then execute bundled scripts and resources on demand. This keeps context small while exposing many capabilities, and the format is an open standard adopted across vendors.
Tool Retrieval (Tool RAG)(TR)
When an agent can reach hundreds or thousands of tools or MCP servers, loading every schema into the prompt is expensive and hurts selection accuracy. Tool retrieval indexes tool definitions and, for each query, retrieves only the semantically relevant ones (embedding search, active discovery, and reranking) before the model chooses. RAG-MCP reports tool-selection accuracy rising from about 13 percent to 43 percent while cutting prompt tokens by more than half.
Structured Outputs(SO)
Guarantee that model output conforms to a schema by constraining decoding. A JSON Schema, regex, or grammar is compiled into a finite-state machine, and at every decode step the tokens that would violate the schema are masked out so only valid continuations can be sampled. In strict mode this makes malformed JSON and invalid tool arguments impossible. It is available natively at OpenAI, Google, and Anthropic and in open libraries such as Outlines and vLLM.
Code as Action (CodeAct)(CA)
Instead of emitting one JSON tool call per turn, the agent's action space is executable code that orchestrates tools with loops, conditionals, and variables. A single code block can call many tools, branch on results, and keep intermediate data in the runtime rather than passing every result back through the context window. Anthropic reports roughly a 98 percent token reduction on some multi-tool workflows when tools are called from code via MCP.
Structured Reflection (Think Tool)
A dedicated no-op "think" tool (Anthropic) declared in the agent tool schema that the model calls mid-trajectory to append structured reasoning between a tool result and the next action. The call has no external effect and returns nothing useful: it simply gives the model a checkpoint to re-read policy, verify constraints, and plan before acting inside a long tool-call chain. Anthropic reports a 54% relative improvement on the tau-bench airline pass^1 metric (0.570 versus a 0.370 baseline) when the tool is paired with a prompt that shows how to use it. Distinct from `metacognitive-monitoring`: that entry is the general capability of monitoring one's own reasoning, whereas the think tool is a concrete tool-schema mechanism for it, separate from extended or inference-time thinking that happens before the first response.
MCP Gateway (Tool Federation & Governance)(MCPG)
A single governed MCP entrypoint that sits in front of many backend MCP servers as a reverse proxy, federating their tools into one curated, managed tool surface that the agent connects to. Every tool call routes through the gateway, which enforces centralized authentication, per-tool authorization that separates the caller's identity from the downstream server's permissions, policy checks, rate limiting, audit logging, and telemetry. This turns a sprawling pile of independently deployed servers into one controlled integration contract, so tools can be curated, versioned, and revoked without touching each agent. Distinct from `control-plane`: the control plane is the general pattern of exposing one interface while routing internally to any tool, service, or model, whereas the MCP gateway is the MCP-ecosystem-specific realization focused on federating many MCP servers and governing the shared tool-access surface.
Patterns Pack
Take the whole catalog with you: MCP server, editor rules and skills, and data.
The Agent Architect
One pattern, one tradeoff, one production failure story. A short weekly briefing for people building agentic systems.
Weekly email, one-click unsubscribe. We only use your address to send the briefing.
From the engineer behind this catalog
Get your agent architecture reviewed
This page documents one pattern. Your system runs dozens, and most failures live in how they fit together. Have the whole design reviewed against the 288 patterns in this catalog: architecture, reliability, evaluation and cost, every finding mapped to the pattern that fixes it.
€750 instead of €1,500, one week, written report and walkthrough call, until 30 September