Module 2 · Building Agents · scripted
Protocols and Function Calling
Overview
Until now, both participants in every conversation were intelligent readers. A computer is not — it can only parse what it expects. For the computer to hold up its end of the conversation, the LLM must speak its actions in a protocol: a rigid, machine-readable form of the language of action that a program can automatically detect and parse. In this lesson, we teach a protocol inside the prompt, see why a probabilistic speaker sometimes breaks it, and learn how function calling builds the protocol into the model's training itself.
Two intelligent participants — until now
Look back at every conversation so far and see it concretely. The messages were rich, loose, full of nuance — "the batter is really thick, almost like dough," "warm at the edges, cold in the middle." A human reads those effortlessly. So does an LLM.
A computer does not. Without an LLM to interpret them, computers can only process messages in very constrained formats. If the computer is going to become the other participant in the conversation, the LLM has to produce its actions in a format the computer can automatically detect and parse: which tool is being requested, with what parameters.
A protocol
What we have to build is a protocol: the syntax, the semantics, and the timing governing the messages exchanged in the conversation.
A protocol has three parts
We teach the LLM the protocol in the prompt that starts the conversation — and it restricts itself to outputs in that format:
You have the following tools available for use:
- measure( ingredient, amount )
- combine( bowl, items )
- whisk( bowl, until )
- griddle( heat: LOW | MED | HIGH, minutes )
- pour( amount, destination )
Task: Help me make sveler.
Rules:
- You must request every action in exactly this format:
Use: <tool>, <parameters>— nothing else in the message. - One action per message; I will report what happened after each.
Use: measure, eggs, 2
Done. 2 eggs measured.
Use: combine, bowl, eggs + 1 dl sugar
Here is why that matters so much. A message like Use: combine, bowl, eggs + 1 dl sugar can be broken apart by a completely ordinary program — split
on the colon, split on the commas, look up the tool name, hand over the
parameters. No intelligence required. Which means the human reading
these messages and doing the work can be replaced by a computer that
detects the pattern, executes the action with traditional computing
tools, and writes back a description of what changed. Everything
computers have been able to do for decades — files, databases, networks,
devices — can now be connected to the LLM through this narrow, parseable
channel.
However: the LLM is probabilistic
But there is a catch. An LLM is not guaranteed to follow the format. It is a next-word predictor, and sometimes the most natural continuation includes a little commentary:
Perfect, the batter looks ready! Now let's get cooking — Use: griddle, MED for about 3 minutes
FORMAT ERROR. Use exactly: "Use:
Use: griddle, MED, 3
Function calling: a high guarantee
Because this problem is so central, frontier models provide a special way of prompting for it, called function calling (or function prompting). The conversation is presented to the LLM together with a list of tools and their parameters — and the model is constrained so that its next output is, with high guarantee, the selection of exactly one of the provided tools, with parameters that follow what the tool specifies, in a fixed format that is easy to detect:
Function calling
A special mode of prompting with a guarantee: the LLM selects one tool from the list you provide, and supplies its parameters in the allowed format — no commentary, no prose, nothing else.
The exact output format is built in and mandated by the maker of the model — you don't design it, and you don't parse anything exotic. What you supply is exactly what we have already built: tools, with names, descriptions, and parameters. The model typically selects one tool per turn (more than one is possible), and its parameters respect the constraints you declared. The guarantee is high, not absolute — but it is a different world from "please follow the format."
The intelligence mismatch
Step back, because there is a clean way to see everything in this lesson. The LLM is much more intelligent and flexible than the computer — and that creates a mismatch at the interface. Between a human and an LLM there is very little friction: both sides repair ambiguity effortlessly. The moment a computer becomes the other side of the conversation, one participant can no longer repair anything.
Friction at the interface
Function calling is how we manage the mismatch: it puts the LLM into a special, rigidly structured conversational mode — essentially forcing it to switch into the language of the computer: simplified, strict syntax, no improvisation. The intelligence stays; the flexibility of expression is deliberately constrained, so the least intelligent participant in the conversation can still do its job.
Design a protocol for one task in your domain: define the syntax, semantics, and timing, then run a human-in-the-loop conversation under it. Try to make the LLM break your format — then tighten the prompt until it holds for ten consecutive actions.