Module 1 · Foundations of Agentic AI · scripted

Protocols and Function Calling

25 minoutcomes: tool-design, agent-architectures

Two intelligent participants — until now

Look back at every conversation so far and notice something: both participants were intelligent. 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

Syntaxthe exact structure of a message "Use: <tool>, <parameter>, <parameter>"
Semanticswhat the message means "Use: griddle, MED, 3" = put the pan on medium heat for 3 minutes
Timingwhen messages may be sent, and how many at once one action per turn; wait for the result before the next

We teach the LLM the protocol in the prompt that starts the conversation — and it restricts itself to outputs in that format:

Example 1 · The cooking conversation, structured
user

You have the following tools available for use:


  1. measure( ingredient, amount )
  2. combine( bowl, items )
  3. whisk( bowl, until )
  4. griddle( heat: LOW | MED | HIGH, minutes )
  5. pour( amount, destination )

Task: Help me make sveler.

Rules:

  1. You must request every action in exactly this format: Use: <tool>, <parameters> — nothing else in the message.
  2. One action per message; I will report what happened after each.
assistant

Use: measure, eggs, 2

user

Done. 2 eggs measured.

assistant

Use: combine, bowl, eggs + 1 dl sugar

user

Done. Eggs and sugar in the bowl.

assistant

Use: whisk, bowl, pale and foamy

user

Done. Pale and foamy.

assistant

Use: griddle, MED, 3

NoteCompare this with the first sveler conversation. Same dish, same loop — but the rich prose is gone, and every action is now a short, rigid, predictable string.

Here is why that matters so much. A message like Use: whisk, bowl, pale and foamy 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:

Example 2 · The protocol drifts
assistant

Perfect, the batter looks ready! Now let's get cooking — Use: griddle, MED for about 3 minutes

NoteCount the failures: a friendly preamble before the message, "MED for about 3 minutes" instead of "MED, 3", and a missing comma. A human wouldn't blink. A program doing string-splitting is now stuck — and whatever it does next, the conversation's trajectory has a problem in it.
user

FORMAT ERROR. Use exactly: "Use: , "

assistant

Use: griddle, MED, 3

NoteRecoverable — but at the cost of an extra turn, every time it happens. A format that holds 49 times out of 50 still breaks the loop the 50th time.

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:

The shape of function calling

Given:the conversation so far
Plus:the tools it may choose from griddle(heat: LOW | MED | HIGH, minutes: 1–10) whisk(bowl, until) pour(amount, destination)

The next output WILL be one selection, well-formed:

griddle(heat=MED, minutes=3)

— not commentary, not prose, not an almost-right variation.

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.

The mismatch, in your world
  • Where in your own research does an intelligent, flexible thing have to talk to a rigid, literal one? What plays the role of the protocol?
  • What would "function calling" look like for that interface?
Your turn

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.