By Sagar Shankaran, Founder of CallSphere
A deep technical walkthrough of how large language models invoke external tools via function calling, covering token-level mechanics, schema injection, and reliability patterns.
Key takeaways
Large language models were originally designed to predict the next token in a sequence. Yet in 2025-2026, tool use has become a first-class capability across GPT-4o, Claude, Gemini, and open-source models like Llama 3.3. Understanding how function calling works beneath the surface is critical for anyone building AI-powered applications.
When you define tools in an API call, the provider serializes your function schemas into the model's context. For example, with OpenAI's API:
{
"tools": [{
"type": "function",
"function": {
"name": "get_weather",
"description": "Get current weather for a location",
"parameters": {
"type": "object",
"properties": {
"location": { "type": "string" },
"unit": { "type": "string", "enum": ["celsius", "fahrenheit"] }
},
"required": ["location"]
}
}
}]
}
This JSON schema gets converted into a structured prompt segment that the model sees as part of its system context. The model has been fine-tuned (via RLHF and supervised fine-tuning on tool-use datasets) to recognize when a user query requires tool invocation and to emit a structured JSON response matching the schema.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent for auto shop in your browser — 60 seconds, no signup.
Under the hood, function calling works through constrained decoding:
flowchart TD
HUB(("From Text Completion to<br/>Tool Invocation"))
HUB --> L0["How Tool Definitions Reach<br/>the Model"]
style L0 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L1["The Token-Level Mechanics"]
style L1 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L2["Parallel and Sequential Tool<br/>Calls"]
style L2 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L3["Reliability Challenges"]
style L3 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L4["Production Hardening<br/>Patterns"]
style L4 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L5["The Bigger Picture"]
style L5 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
style HUB fill:#4f46e5,stroke:#4338ca,color:#fff
tool_use or function_call) instead of the normal end-of-turn tokenModern LLMs support parallel tool calling, where the model requests multiple function invocations in a single turn:
# Claude's tool_use response may contain multiple tool blocks
for block in response.content:
if block.type == "tool_use":
result = execute_tool(block.name, block.input)
tool_results.append({
"type": "tool_result",
"tool_use_id": block.id,
"content": result
})
Sequential tool calls happen when the model needs the output of one tool to determine the input of the next. The model handles this by making a single tool call, receiving the result, then deciding whether to call another tool or respond to the user.
Tool use introduces several failure modes:
Still reading? Stop comparing — try CallSphere live.
See the auto shop AI agent handle a real call — complete, industry-specific, and live in your browser. No signup.
Teams shipping tool-use systems in production adopt several patterns:
Tool use transforms LLMs from knowledge retrieval systems into action-taking agents. As tool ecosystems mature through standards like Anthropic's Model Context Protocol (MCP), the boundary between "chatbot" and "software agent" continues to blur.
Sources: Anthropic Tool Use Documentation | OpenAI Function Calling Guide | Gorilla LLM Research
flowchart LR
IN(["Input prompt"])
subgraph PRE["Pre processing"]
TOK["Tokenize"]
EMB["Embed"]
end
subgraph CORE["Model Core"]
ATTN["Self attention layers"]
MLP["Feed forward layers"]
end
subgraph POST["Post processing"]
SAMP["Sampling"]
DETOK["Detokenize"]
end
OUT(["Generated text"])
IN --> TOK --> EMB --> ATTN --> MLP --> SAMP --> DETOK --> OUT
style IN fill:#f1f5f9,stroke:#64748b,color:#0f172a
style CORE fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style OUT fill:#059669,stroke:#047857,color:#fff
flowchart TD
HUB(("From Text Completion to<br/>Tool Invocation"))
HUB --> L0["How Tool Definitions Reach<br/>the Model"]
style L0 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L1["The Token-Level Mechanics"]
style L1 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L2["Parallel and Sequential Tool<br/>Calls"]
style L2 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L3["Reliability Challenges"]
style L3 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L4["Production Hardening<br/>Patterns"]
style L4 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
HUB --> L5["The Bigger Picture"]
style L5 fill:#e0e7ff,stroke:#6366f1,color:#1e293b
style HUB fill:#4f46e5,stroke:#4338ca,color:#fff

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
GPT-Realtime-2 brings GPT-5-class reasoning into voice. What that means for tool-call reliability, structured output, and production agent design.
A clean before/after of agent architecture in 2026. The control loop moved from your framework code into the model's reasoning chain. What that looks like.
Workspace Studio puts a Gemini-powered AI agent builder inside Google Workspace. A walkthrough of what it does, who it is for, and where it fits in 2026.
Google's May 2026 MCP 1.0 + A2A developers guide is the cleanest protocol picker we have seen. The takeaways, in plain English, with a CallSphere lens.
Gemini 3.1 Ultra ships with a 2-million token context window and full text, image, audio, and video multimodality. What changes and how to build for it.
How the modern agent eval stack actually flows: instrument, trace, dataset, evaluator, score, CI gate. The full pipeline that keeps agents from regressing.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco