Function Calling (Tool Calling)
Function calling lets an LLM request structured invocations of your code: describe tools with schemas, the model emits typed calls, your app executes them.
Function calling (tool calling) is the mechanism that lets language models act: you declare functions with JSON-schema parameters, the model responds with a structured call — name plus typed arguments — and your application executes it and feeds back the result.
It's the bridge from text generation to action, and the atom every agent loop is built from: model emits call → app executes → result returns as an observation → model decides the next step. The model never runs anything itself; it produces intentions shaped by your schemas, which is exactly why the engineering quality lives in those schemas — sharp names, described parameters, disjoint purposes (tool-definition-generator automates the shape).
Production reliability has one golden rule: feed errors back as observations. A failed call isn't an exception to crash on — it's information the model uses to retry correctly ("invalid date format" → reformatted call). That pattern, plus validation, idempotency, and permission gating, is the substance of Production Tool & Function Calling. The Model Context Protocol standardizes the layer above: where tools come from and how clients discover them.
Frequently asked questions
- Does the model actually execute the function?
- No — it only emits a structured request (the function name plus JSON arguments matching your schema). Your application executes the real call and returns the result to the model as an observation. The model proposes; your code disposes — which is also where validation, permissions, and safety checks belong.
- How does function calling relate to MCP?
- Function calling is the model-level mechanism (emit a structured call); MCP is the protocol layer that standardizes where tools come from — servers any client can connect to, with discovery and transport handled. MCP tools are surfaced to the model as functions; one is the interface, the other the ecosystem.
Related
- Production Tool & Function Calling: Feed Errors Back as ObservationsHow agents use tools — the call/observe/retry loop, why errors must return to the model, and the schemas, idempotency, and limits that keep it reliable.
- AI AgentAn AI agent is an LLM-driven system that pursues a goal in a loop — calling tools, observing results, iterating — instead of returning one answer.
- Structured OutputStructured output makes an LLM return data in a guaranteed shape — JSON matching your schema — so code can consume model responses without parsing prose.
- MCP (Model Context Protocol)MCP is the open standard for connecting AI models to external tools and data: write one server, and any MCP client — Claude Code, IDEs, agents — can use it.
- Tool Definition GeneratorGenerate clean function/tool schemas for an LLM agent from existing code or a spec — accurate JSON Schema, model-facing descriptions, honest required fields, and enums that make invalid calls impossible. Use when wiring functions into an agent's tool-calling loop.
- Agent Tool Integration EngineerUse this agent to wire tools and function-calling into an agent loop reliably — clean tool schemas, errors fed back as observations, retries with limits, idempotency, and parallel calls. Examples — "connect our APIs as agent tools", "our agent calls tools wrong / ignores tool errors", "add function-calling with proper error recovery to our agent".