Tool use (function calling)
Overview
Tool use lets a model call functions you define: search a database, call an API, run code, edit files. The model does not run anything itself. It returns a structured request (tool name plus JSON arguments); your code runs it and sends back the result. This is how LLMs act in the world and the core of every agent.
Key concepts
- Tool definition: name, description, and JSON Schema for the inputs. The description is a prompt: it is how the model knows when and how to use the tool.
- Loop: request, then
tool_useresponse, run the tool, sendtool_result, repeat until the model gives a final answer. - Parallel tool calls: several calls in one turn; return all results together.
- Strict mode: guarantees arguments match the schema exactly.
- Server tools: tools the provider runs for you (web search, web fetch, code execution).
- Tool search / deferred loading: with many tools, load definitions only when needed
to save context. Now offered by Anthropic (tool search), OpenAI's Agents SDK
(
ToolSearch, alpha), and the Gemini API (tool retrieval, preview since 2026-11-19:defer_loading: trueon tools or remote MCP servers plus a{"type": "tool_search"}tool, orexecution: "client"for your own retrieval; Gemini 3.6 and later). Pydantic AI'sToolBridge(2.71.0) does the same inside the framework withtool_search,tool_describe, andtool_call, which keeps the prompt cache stable. - Programmatic tool calling: the model writes code that calls your tools, so large
intermediate results never enter its context. "Code mode" proxies apply this to MCP:
MCPtoCodeMode (2026-10-22) puts any set of MCP servers behind
search,describe, andexecute, and runs the model's JavaScript in a QuickJS sandbox. - Tool runners: SDK helpers that run the loop for you.
- Standard connections: MCP packages tools as reusable servers.
- Forcing a tool:
tool_choicecan require a tool call on many APIs, but Claude Fable 5.1, Opus 5.5, and Sonnet 5.5 reject forcedtool_choice(anyortool); useautowith clear instructions, strict schemas, or structured outputs instead. - Hosted computer use: providers increasingly run the browser or desktop for the
agent (OpenAI's Agents API since 2026-09-29), while the application handles site
approvals and sign-in. The client-run model remains common: Gemini's Computer Use tool
(GA 2026-10-30) only proposes browser, desktop, or mobile actions, and the client runs
them and handles safety confirmations. Computer use has also reached small models:
Claude Haiku 5.5 (2026-10-07) and Gemini 3.5 Flash-Lite support it. Gemini's Computer
Use offers per-action
safety_decisionconfirmations and opt-in prompt injection detection (see Gemini). - Rich tool results: results need not be text. Since 2026-11-05 Gemini function responses can carry Office and OpenDocument files, audio, and video (see Gemini).
- CLIs as tools: instead of an MCP server, a vendor can ship one binary built for
agents to discover and call. Google's
gemini-apiCLI (beta, 2026-10-27) has--help,--schema,--dry-run, and-o json, plus a suggestedCLAUDE.md/AGENTS.mdsnippet instead of a skill. Small shell tools work the same way: webframe (MIT, Go) runs a page in the system's web view, prints console output to stdout, and takes JavaScript on stdin (go install tractor.dev/webframe/cmd/webframe@latest). Simon Willison found it fast for scraping but limited (CSP failures, a 0×0 viewport, hanging loads, no HTTP metadata; 2026-10-26). - Tools called from code: instead of one tool call per model turn, the model writes a
short program that calls several tools, chains results, and returns only what it needs
to read. MCP proxies such as MCPtoCodeMode did this first; Claude Code has it built in
as experimental Code Mode (2.1.323+,
CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1; see coding agents). The trade-off is review: in Claude Code's auto mode the safety classifier sees the program once, not each call, so values computed at run time escape it; per-call rules and hooks still apply.
How to use it
- Write tool descriptions like documentation for a new colleague: purpose, when to use, input meaning, examples, edge cases.
- Prefer a few well-designed tools over many overlapping ones.
- Return concise, high-signal results; truncate or paginate big outputs.
- Return errors as tool results (with an error flag) so the model can recover.
- Validate inputs and require confirmation for destructive actions. Frameworks now build
this in: the OpenAI Agents SDK 0.24 previews (alpha.8, 2026-11-16) let you review a
Python tool call's arguments and approve or reject it, optionally for the rest of the
session, and Pydantic AI 2.71.0 (2026-11-18) adds
PermissionRuleto allow, ask, or deny tool and shell calls by rule.
Current state
- 2026-11-20: Deferred tool loading is in preview or alpha at two of the three
vendors (Gemini tool retrieval, OpenAI Agents SDK
ToolSearch); expect GA and API changes. Claude Code's Code Mode is still experimental. - 2026-10-30: Gemini API Computer Use is GA on Gemini 4 Argon, 3.8 Flash, and 3.5 Flash-Lite; rate limits are not yet published.
- 2026-10-22: MCPtoCodeMode's claim of about 5.7× fewer input tokens is self-reported; see MCP for install commands.
Open questions
- Best practices for very large tool catalogues (hundreds of tools). Two approaches so far: tool search / deferred loading, and code-mode proxies that hide tools behind search and execute (2026-10-22). There is no independent comparison of the two yet. By 2026-11-20 deferred loading is supported by Anthropic, Google, and OpenAI's Agents SDK, so it is the de facto default; code mode remains vendor- or proxy-specific.
Sources
- ReAct
- Claude models overview
- OpenAI API changelog: GPT-6.1 Sol
- Claude Haiku 5.5
- MCPtoCodeMode
- webframe
- Gemini API CLI (gemini-api) beta
- Gemini API changelog, 2026-11-05
- Gemini API Computer Use generally available
- Run tool calls from code with Code Mode
- OpenAI Agents SDK v0.24.0-alpha.8
- Gemini API: tool retrieval (preview) and Genie 4 GA
- Pydantic AI v2.71.0