Agents

Tool use (function calling)

Last reviewed 22 November 2026

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_use response, run the tool, send tool_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: true on tools or remote MCP servers plus a {"type": "tool_search"} tool, or execution: "client" for your own retrieval; Gemini 3.6 and later). Pydantic AI's ToolBridge (2.71.0) does the same inside the framework with tool_search, tool_describe, and tool_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, and execute, 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_choice can require a tool call on many APIs, but Claude Fable 5.1, Opus 5.5, and Sonnet 5.5 reject forced tool_choice (any or tool); use auto with 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_decision confirmations 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-api CLI (beta, 2026-10-27) has --help, --schema, --dry-run, and -o json, plus a suggested CLAUDE.md/AGENTS.md snippet 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 PermissionRule to 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