AI Agent Tool Calling: How Agents Use APIs, Functions & External Tools

COMPLETE guide to AI agent tool calling in 2026. How agents call APIs, define tools, handle errors & use parallel tools. OpenAI, Anthropic & Google.

Quick answer: AI agent tool calling is the mechanism by which an LLM issues a structured request to invoke an external function, API, or service. The model doesn't execute the code itself — it outputs a JSON call spec, your application runs it, and the result flows back into the agent's context. This loop is what separates an AI agent from a chatbot.


Tool calling is the most important capability in modern AI agents — and the most misunderstood. Most explanations treat it as a simple API feature. In reality, tool calling is the entire bridge between language models and the real world.

Without tools, an LLM can only generate text. With tools, it can query a database, send an email, execute code, book a meeting, or trigger a deployment. Every AI agent you've seen do something genuinely useful — from GitHub Copilot fixing a bug to an AI SDR scheduling a call — is doing it through tool calls.

This guide explains how tool calling actually works, how to define tools that agents use correctly, how to handle failures in production, and where MCP fits into the picture.


What Is AI Agent Tool Calling?

AI agent tool calling (also called function calling or tool use) is a native capability of modern LLMs that lets the model request the execution of a specific function with specific parameters — rather than just describing what it would do.

Here's the key distinction: the LLM does not run the code. It outputs a structured call specification — a JSON object with a function name and arguments. Your application receives that spec, executes the real function (an API call, database query, calculation, etc.), and returns the result to the model as a new message.

The model then incorporates the result into its reasoning and either calls another tool or generates a final response.

This design has a critical implication: every tool call is mediated by your application code. You decide which tools are available, what permissions they have, and what happens when they fail. The model is the decision-maker; your application is the executor.

Terminology Note

OpenAI coined "function calling" in 2023. Anthropic uses "tool use." Google uses both. By 2026 the community has broadly converged on "tool calling" as the standard term, since the concept has expanded far beyond simple functions to include APIs, MCP servers, browser actions, and code interpreters.


How Tool Calling Works: The 5-Step Flow

Understanding the mechanics makes the difference between agents that work and ones that don't.

1

You define tools in the system prompt

Before the conversation starts, you provide the LLM with a list of available tools. Each tool has a name, a natural language description, and a JSON schema defining its input parameters. The model reads these definitions to understand what capabilities it has.

2

The LLM decides which tool (if any) to call

When the user sends a message, the model reasons about whether it can answer directly or needs to call a tool. If it needs a tool, it selects the most appropriate one based on the descriptions you provided and generates a structured call with the required arguments filled in.

3

Your application receives the call spec and executes it

The model's response contains a tool call block — not a text answer. Your code parses this, extracts the function name and arguments, runs the actual function (the real API call, database query, etc.), and captures the result.

4

The result is returned to the model as a tool result

You send the function's output back to the model in a specially formatted message (a "tool result" block). The model now has real-world data it can reason with.

5

The model generates its final response (or calls another tool)

With the tool result in context, the model either answers the user's question using the retrieved data, or decides it needs another tool call to gather more information. This loop continues until the task is complete.

What This Looks Like in Practice

A concrete example: a user asks an agent "What's the weather in Berlin and do I have any meetings this afternoon?"

  1. The model sees two independent needs: weather data and calendar data
  2. It issues parallel tool calls: get_weather(city="Berlin") and get_calendar_events(date="today", time_range="afternoon")
  3. Both functions execute simultaneously — your app calls the weather API and the calendar API
  4. Both results come back: {temp: 12, condition: "cloudy"} and [{title: "Design Review", time: "14:00"}]
  5. The model combines both into a natural response: "It's 12°C and cloudy in Berlin. You have a Design Review at 2 PM this afternoon."

No hallucination. Real data. The whole round-trip takes ~500ms for the tool calls plus the model's final inference pass.


Types of Tools AI Agents Use

Tool calling isn't limited to REST API calls. Modern agents can invoke a wide range of tool types:

🌐
API & Web Calls

REST APIs, GraphQL endpoints, webhooks. Search the web, query SaaS platforms (Slack, Notion, Salesforce), fetch live data. The most common tool type.

🗄️
Database Queries

Read from (and sometimes write to) SQL databases, vector stores, key-value caches. Agents use these to retrieve structured data and long-term memory.

⚙️
Code Execution

Run Python, JavaScript, or shell commands in a sandboxed environment. Essential for data analysis, calculations, and file processing agents.

📄
File & Document Operations

Read PDFs, write files, parse spreadsheets, manipulate images. The agent's interface to the local or cloud file system.

🖥️
Browser & Computer Use

Navigate web pages, click buttons, fill forms, take screenshots. AI browser agents use this to automate any task a human could do in a browser.

🤖
Agent-to-Agent Calls

One agent calling another specialized agent as a tool. The foundation of hierarchical multi-agent systems. See AI agent architecture for patterns.


Anatomy of a Tool Definition

The quality of your tool definitions directly determines how accurately the agent uses them. Here's what a well-defined tool looks like:

{
  "name": "get_customer_order",
  "description": "Retrieves a specific customer order by order ID. Use this when the user asks about order status, shipping details, or order contents. Returns order status, items, total, and estimated delivery date.",
  "parameters": {
    "type": "object",
    "properties": {
      "order_id": {
        "type": "string",
        "description": "The order ID, formatted as ORD-XXXXXX (e.g., ORD-483920)"
      },
      "include_tracking": {
        "type": "boolean",
        "description": "Set to true to include real-time shipping tracking information in the response"
      }
    },
    "required": ["order_id"]
  }
}

Every field matters:

  • name — snake_case, descriptive, unique. The model uses this to reference the tool in its reasoning.
  • description — This is the single most important field. Tell the model when to use this tool, not just what it does. Ambiguous descriptions cause the model to either miss the tool or use it incorrectly.
  • parameters.properties[field].description — Explain format constraints, examples, and edge cases. The more specific, the fewer hallucinated parameter values.
  • required — List only truly required parameters. Optional parameters give the model flexibility; unnecessary required parameters cause failures.
The #1 Tool Calling Mistake

Writing descriptions that only say what a tool does, not when to use it. "Gets weather data" is a bad description. "Use this to retrieve current temperature, humidity, and conditions for any city. Call this when the user asks about weather, packing for travel, or outdoor activity planning" is a good one. The difference is context — the model reads descriptions to make selection decisions, not to understand implementation.


Parallel Tool Calling

One of the most impactful performance features of modern LLMs is the ability to issue multiple tool calls in a single response when the calls are independent of each other.

Consider a research agent asked to "compile a competitive analysis of three companies." Instead of:

call get_company_info("Acme Corp") → wait → call get_company_info("Beta Inc") → wait → call get_company_info("Gamma Ltd") → wait

With parallel tool calling it does:

call get_company_info("Acme Corp")   ┐
call get_company_info("Beta Inc")    ├── all execute simultaneously
call get_company_info("Gamma Ltd")   ┘

The latency drops from 3 × API_latency to 1 × API_latency. For agents with many sequential tool calls, parallel execution can cut total runtime by 50–80%.

How to enable it: Parallel tool calling is on by default in OpenAI and Anthropic APIs. You can disable it (OpenAI: parallel_tool_calls: false) when you need tools to execute sequentially — for example, when tool B depends on tool A's output.

Design for Parallelism

When designing your tool set, identify which tools are always independent (they can always run in parallel) and which have dependencies (B needs A's result). Structure your agent workflow to batch independent calls. This single optimization often delivers more latency improvement than upgrading to a faster model.


Tool Calling vs. the Model Context Protocol (MCP)

As your agent's tool set grows, you'll hit a scaling problem: defining and maintaining dozens of tool schemas in every agent is repetitive and brittle. This is exactly the problem that MCP (Model Context Protocol) solves.

Direct Tool CallingWith MCP
Tool definitionInline in each agent's promptDefined once in an MCP server
ExecutionYour app code runs the functionMCP server handles execution
SharingCopy-paste schemas between agentsAny agent connects to the same server
DiscoveryStatic — you list tools upfrontDynamic — agents can discover tools
Auth & permissionsImplement per-toolCentralized in the MCP server

Think of MCP as a standardized tool registry: you build a tool once (as an MCP server), and any compatible agent can connect and use it without re-implementing the schema or execution logic.

For a deep dive on how to build and deploy MCP servers, see How to Build an MCP Server. For a comparison of MCP with the A2A protocol, see MCP vs. A2A.


Tool Calling Across Platforms

The mechanics are nearly identical across the major LLM providers — they just use slightly different API shapes:

ProviderTerm UsedDefinition FormatParallel CallsStrict Mode
OpenAI (GPT-4o, o3)Function calling / ToolsJSON Schema in `tools` array✅ Default on✅ `strict: true` enforces schema
Anthropic (Claude 3.5/4)Tool useJSON Schema in `tools` array✅ Default on✅ `strict: true` available
Google (Gemini 2.0/2.5)Function calling / ToolsFunctionDeclaration objects✅ Supported⚠️ Via `mode: ANY` forcing
Mistral / Llama 3.3Function callingJSON Schema (OpenAI-compatible)✅ Supported in larger models❌ Not standardized

The practical advice: if you're building multi-provider agents, abstract your tool definitions through a standard schema layer (like what OpenAI's Agents SDK or the Claude Agent SDK provides) so you can swap models without rewriting tool logic.


Error Handling for Tool Calls

Tool calls fail. APIs go down, rate limits hit, parameters get misformatted. How your agent handles these failures is the difference between a brittle prototype and a production-grade system.

Return structured errors, not exceptions. When a tool fails, don't propagate a raw Python traceback or HTTP 500 response to the model. Return a descriptive error object:

{
  "error": true,
  "error_code": "RATE_LIMITED",
  "message": "GitHub API rate limit exceeded. Resets in 47 seconds.",
  "retry_after": 47
}

With this structure, the model can reason: "The GitHub tool is rate-limited for 47 seconds. I'll proceed with the information I already have and note that live repo data wasn't available."

The three tiers of tool failure handling:

  1. Retry with backoff — For transient errors (rate limits, network timeouts). Retry 2–3 times with exponential backoff before escalating. Implement this in your execution layer, not in the agent loop.

  2. Fallback tool — For persistent failures. If get_live_stock_price fails, try get_cached_stock_price. Design your tool set with fallback pairs for critical capabilities.

  3. Graceful degradation — When all options fail, the agent should surface a clear, honest message to the user rather than hallucinating a plausible-sounding answer. "I wasn't able to retrieve your account balance — the banking API is temporarily unavailable" is better than a made-up number.

Never Silently Swallow Errors

The most dangerous failure mode is a tool that catches all exceptions and returns an empty result. The agent has no idea the tool failed — it assumes silence means success and proceeds with incorrect assumptions. Always return a structured error response. Always.


Security: Tools That Can Act Need Permission Boundaries

Every tool your agent can call is a potential attack surface. A research agent that can also delete records or send emails has an unnecessarily large blast radius.

The principle of least privilege applies directly to tool design:

  • Give each agent only the tools it needs for its specific task
  • Separate read tools from write tools — expose read-only tools by default
  • For irreversible actions (send email, delete record, trigger payment), add a human-in-the-loop confirmation step
  • Log every tool call with its inputs, outputs, and the agent's reasoning — this is your audit trail

For a full treatment of tool-level security, see our guide on AI agent security and AI agent guardrails.


Tool Calling Best Practices Checklist

Before deploying agents with tool calling in production:

  • ✓Write "when to use" descriptions: every tool description explains the scenario that should trigger it, not just what it does.
  • ✓Include format examples in parameter descriptions: show the expected format (e.g., "ISO 8601 date like 2026-03-14") to prevent hallucinated parameter values.
  • ✓Enable strict mode: use strict: true in OpenAI/Anthropic to enforce schema compliance and eliminate type mismatch errors.
  • ✓Design for parallelism: identify which tools can always run in parallel and structure your agent flow to batch them.
  • ✓Return structured errors: all tool failures return a descriptive JSON error object — no raw exceptions, no silent empty responses.
  • ✓Implement retries at the execution layer: transient failures retry with exponential backoff before the agent sees an error.
  • ✓Scope permissions tightly: each agent has only the tools it needs; destructive tools require human approval.
  • ✓Log every tool call: name, parameters, result, latency, and token cost — this is your observability foundation.
  • ✓Cap your tool set: if an agent has more than 12–15 tools, use dynamic tool loading to expose only relevant tools per task phase.
  • ✓Test failure paths: deliberately trigger each tool's error response in staging and verify the agent handles it gracefully.

How Many Tools Is Too Many?

Research on LLM tool selection accuracy consistently shows degradation as the tool set grows. The practical guidance:

Tool CountSelection AccuracyRecommendation
1–5 tools~98%Fine — expose all
6–10 tools~93%Fine — write clear descriptions
11–15 tools~85%Acceptable — group related tools
16–25 tools~70%Use dynamic tool loading
25+ tools<60%Mandatory dynamic loading or sub-agents

Dynamic tool loading means you don't expose all tools in every turn. Instead, you identify the current task phase (research, drafting, reviewing) and load only the tools relevant to that phase. Frameworks like LangGraph and the OpenAI Agents SDK support this natively.

An alternative is to delegate to specialist sub-agents, each with a focused tool set. A "web research" sub-agent with 5 search tools will outperform a general agent with 30 mixed tools. See AI agent architecture patterns for how to structure hierarchical agent systems.


Get Started

Tool calling is the mechanism — the AI agent architecture around it determines whether your agent is reliable in production. Once your tool layer is solid, the next bottleneck is usually context engineering: deciding exactly what state, history, and retrieved knowledge the agent has in its context window at each step.

cowork.ink gives teams a managed tool registry and execution layer for production AI agents — standardized tool definitions, permission controls, retry logic, and structured logging built in. Your agents get reliable tool calling without building the infrastructure from scratch.

To connect your tools to any compatible agent using an open standard, explore how to build an MCP server — the protocol that turns your tools into a reusable, shareable service.

Frequently Asked Questions

What is tool calling in AI agents?
Tool calling is the mechanism that lets an LLM trigger external functions, APIs, or services during a conversation. Instead of just generating text, the model outputs a structured request (name + arguments) to invoke a specific tool — your application executes it and returns the result. This is the core mechanism that turns a chatbot into an AI agent.
What is the difference between function calling and tool calling?
They're the same thing with different branding. OpenAI originally called it "function calling." Anthropic calls it "tool use." Google uses both terms. In 2026 the industry has converged on "tool calling" as the broader term, since tools can be much more than simple functions — they include APIs, code interpreters, browser actions, and entire MCP servers.
Can AI agents call multiple tools at once?
Yes. Modern LLMs support parallel tool calling — the model can decide to call several tools in a single response when their results are independent of each other. This dramatically reduces latency for multi-step tasks (e.g., fetching weather and calendar data simultaneously). OpenAI, Anthropic, and Google all support parallel tool calls.
How do you define a tool for an AI agent?
A tool is defined as a JSON schema with three required elements: a name (snake_case, no spaces), a description (this is what the model reads to decide whether to use the tool), and a parameters object describing the expected inputs and their types. The description is the most important part — a poor description is the #1 cause of tool selection mistakes.
What happens when a tool call fails?
When a tool call fails, the agent receives the error response as an observation in its loop. A well-designed agent will interpret the error, decide whether to retry with different parameters, try a fallback tool, or surface the issue to the user. The key is to return structured, descriptive error messages — not raw stack traces — so the model can reason about what went wrong.
Home Blog Company