Deep-dive

Function calling: how to make an LLM act, not just answer

Function calling (tool use) is what turns a language model from a talker into an agent that executes. How it works, how to design good tools, and the mistakes that break in production.

Jul 22, 2026·9 min read·.md

A language model, on its own, only knows how to do one thing: generate text. It's a brilliant conversationalist and a useless executor. Ask it what your bank balance is and, without help, it'll invent a convincing number — because generating plausible text is literally all it does. Function calling is the bridge between that conversationalist and the real world. It's the mechanism that turns "AI that talks" into "AI that does."

If you want to build agents that solve problems — not chatbots that push the customer to the portal — you need to understand this deeply.

What it really is

Function calling (also called tool use) is the model's ability to decide, in the middle of a conversation, that it needs an external tool and to ask to use it. The flow is this:

  1. You tell the model which tools exist (name, description, parameters).
  2. During the conversation, the model realizes it needs one of them and, instead of replying with text, returns a structured call: get_order(id: "123").
  3. Your code executes that function for real — queries the database, calls the API — and returns the result to the model.
  4. The model uses that real data to continue the conversation: "Your order 123 went out for delivery today."

The point many people get wrong: the LLM doesn't execute anything. It only decides what to call and with which arguments. The one that executes — and validates — is you. That separation is the backbone of a safe agent.

Why this changes everything

Without tools, an LLM's ceiling is giving generic information and, at worst, hallucinating. With tools, it starts operating on the reality of your business: the customer's real data, real inventory, the real payment. The conversation stops being about the problem and starts solving the problem.

That's exactly the difference that separates an AI agent from a chatbot. The chatbot says "for a duplicate invoice, go to the portal." The agent calls generate_duplicate_invoice(customer_id), gets the invoice, and sends the PIX in the conversation. Same question, completely different categories of software — and the difference is well-done function calling.

How to design good tools

The quality of your agent depends more on tool design than on the model. Principles I follow:

Descriptions the model understands. Each tool's description is a prompt. "Fetches information" is bad; "Fetches the delivery status of an order by order number" is good. The model chooses the tool by reading this — be specific.

Typed, minimal parameters. Ask for exactly what the function needs, with clear types. Fewer parameters, fewer chances for the model to fill them in wrong. Enums when the values are fixed.

Atomic tools, not Swiss army knives. A tool that does five things depending on an action parameter confuses the model. Prefer separate open_ticket, check_ticket, close_ticket. Each does one thing well.

Returns the model can use. Return structured, concise data. A giant JSON burns context and confuses. Return the essentials for the next decision.

The mistakes that break in production

I've seen (and made) all of these:

The golden rule

I sum it up like this: the LLM is the brain that decides; the tool layer is the body that acts responsibly. The brain can wander, hesitate, even hallucinate. The body — your code — can't. It validates every intention, confirms what's dangerous, executes what's safe, and logs everything.

Function calling is what makes AI leave the screen and touch the business. But it's also where the risk lives. Doing this layer well is the difference between an agent you trust in production and one you shouldn't have plugged in.


I build AI agents that actually act — with safe function calling, integrated into the business's systems. If you want to move past the chatbot and have AI that executes, let's talk.

Frequently asked questions

What is function calling?

Function calling (or tool use) is a language model's ability to decide to call external functions/APIs during a conversation. Instead of just generating text, the LLM returns a structured request ('call get_order with id=123'), your code runs it and returns the result, and the model continues the conversation with that real data. It's what turns a chatbot into an agent that acts.

What's the difference between function calling and an AI agent?

Function calling is the mechanism; the agent is the system. The agent uses function calling as its 'hand' to act in the world — query systems, create records, process payments — combined with memory, context, and business logic. Without tools, an agent only talks.

Does the LLM run the function itself?

No. The model only decides and proposes which function to call and with which arguments. Your code is what executes it — validating the arguments, running the operation, and returning the result to the model. That separation is crucial: the LLM can hallucinate, but the execution layer validates and stays in control.

LS
Written by Lucas Silva
I build AI products that ship — from diagnosis to production.
Function CallingTool UseLLMAI AgentsAI Engineering

Got a business problem to solve with AI?

Tell me the problem and I'll hand you a product that actually runs.

Get in touch

Keep reading

Guide

Guardrails: how to stop an AI agent from doing something stupid in production

An LLM hallucinates, obeys whoever manipulates it, and gets things wrong with confidence. The practical guide to the guardrails that separate a safe agent from an accident waiting to happen.

Guide

MCP (Model Context Protocol): what it is and why it matters for AI agents

The no-nonsense guide to the Model Context Protocol: what it solves, when to use it, and why it became the 'USB-C' that connects AI agents to your business tools.