Part 0

Agent Smith doesn’t work here

When I hear “agent”, I still picture Agent Smith. The one we’ll build works for a small coffee roastery. Ada would like its help cancelling the right order.

Phillipp Bertram7 min read
  • AI agents
  • LLM
A paper name tag that reads: Hello, my name is Agent Smith. Smith is crossed out. Below it: a small coffee roastery.
Contents7 sections

In this chapter

  • See The finished agent at work: it looks up an order and asks before it cancels one.
  • Learn How language models got from pretraining to calling functions, and what “agent” means in this series.
  • Preview The eleven chapters that build the agent on one map: four by hand, seven with an agent SDK.

How it started for me

When ChatGPT came out at the end of 2022, I was CTO at AeroSys, a startup building Goose, a digital co-pilot for the cockpit. Goose used machine learning and ran entirely without generative AI. I first really took notice of ChatGPT at a workshop in New York. I brought it back to the team, and we looked at whether it belonged in Goose. In principle it would have fitted. In practice Goose had to work offline, so we left it out.

In my work I meet teams that want to use agents without knowing what happens underneath. This series is the explanation I’d have liked when I started. I enjoy taking a complex topic apart until it’s easy to follow and easy to picture.

When someone says “agent”, the first thing I picture is still Agent Smith in The Matrix. I wonder how he’d get on in customer support.

The agent we will build

I like coffee, so I’ve given our agent a job at a small roastery. There’s a café out front. Behind the counter, the staff pull espresso shots and pack beans and brewing gear for the online shop.

Five minutes after ordering two bags of espresso, Ada checks when her new hand grinder is due. She’d forgotten she ordered a whole kilo of beans with it. A kilo and a half of espresso feels like quite a commitment. She’d like to cancel an order. Preferably the one without the grinder.

Ada opens the roastery’s chat with the newer order number, A-1077. When the agent asks you to approve the cancellation, take a look at the items. Two bags of beans and some paper filters? That’s the one.

A run of the finished agent
Ada

Has my order A-1077 shipped yet? If not, please cancel it.

Agent

Looks up order 1077

errorUnknown order "1077". Use one of: A-0981, A-1042, A-1077.

Corrects itself and looks up A-1077

status processing · placed on 2026-11-19 · 2 x espresso beans, 250 g · 1 x paper filters, pack of 100

Wants to cancel A-1077

Waiting for your yes

cancelOrder({"id":"A-1077"})

In each step the model chooses what to do, and your code does it. A script plays the model here, so the run is the same every time. “Terminal” shows what the program prints at the same point.

The first lookup fails because the order number is missing its prefix. The second finds Ada’s order marked processing. Her espresso beans haven’t shipped yet, so the shop can still cancel the order. You get the final say, and Ada gets a different answer depending on what you decide.

In this demo a script plays the part of the language model. That’s how you can replay the same mistake and try both decisions. When we build the program, we’ll start with a real model. If you’d like to try the first call now, jump to chapter 1.

How a model got an order lookup

One early use of machine learning on text was to sort movie reviews into positive and negative ones. Researchers trained classifiers on labelled reviews. For a developer, that meant choosing the task up front. Ada wants something different. The same program needs to understand her question, decide which order to look up and read what comes back. The movie review study

From training a model to calling a function

  1. 2018

    A model gets a head start

    BERT learned patterns from a large collection of text before its authors trained it further on examples of a particular task. That second step is called fine-tuning. One pre-trained model could give several applications a head start. The BERT paper

  2. 2020

    The task fits in the request

    The GPT-3 researchers described tasks and supplied examples in plain text. They could try another task by changing the request, using the same trained model. That’s the starting point for our first chapter. The GPT-3 paper

  3. October 2022

    The next step depends on what comes back

    Weeks before ChatGPT came out, the ReAct researchers had a language model look things up in Wikipedia. It could use the passage it got back to decide what to do next. The agent at the roastery works on the same principle. Looking up Ada’s order tells it whether there’s a parcel to track yet. The ReAct paper

  4. June 2023

    A request your code can run

    OpenAI added function calling to its API. Developers could describe a function and get back its name and arguments. In our shop the model can ask for getOrder with an order number. The TypeScript function reads the record and sends the result back. OpenAI’s function calling announcement

Key detail

The model doesn’t run anything. It returns a function’s name and arguments, and our code decides what to do with them.

Would Agent Smith qualify?

Smith is a program that notices things happening inside the Matrix and acts on them. That’s close to a classic textbook definition. The word was already giving researchers trouble before the film came out. In 1996, Hyacinth Nwana sympathised with the complaint that “everybody is now calling everything an agent”. Sounds familiar. Nwana’s survey

Thirty years later, the people who build agents still word it differently. Here are four definitions, from broad to narrow.

An agent perceives its environment and acts on it.

Russell and Norvig, AI textbook

“Agents are systems that independently accomplish tasks on your behalf.”

OpenAI, practical guide

Agents are “systems where LLMs dynamically direct their own processes and tool usage”.

Anthropic, Building effective agents

“An LLM agent runs tools in a loop to achieve a goal.”

Simon Willison, on LLM agents

So would Smith qualify? By the textbook, yes. OpenAI would ask on whose behalf he works. For Anthropic and Willison he lacks the language model, which is fair for a film from 1999.

I’ll use Willison’s definition for the coffee shop. The large language model (LLM) chooses a step. A tool is a function the program makes available to it, like looking up an order. The loop gives the model the result and another turn. Once it has enough information, it can answer Ada.

Eleven chapters in one picture

Ada types her question in chapter 1. She could also send a screenshot of the tracking page, or ask the same question in a voice message. A model that accepts more than one kind of input is called multimodal. Which kinds it can read or hear depends on the model. OpenAI’s guide to image input · OpenAI’s guide to audio and voice

The diagram starts with that single call. Chapters 2 to 4 add the facts about Ada’s order, give the model a lookup function and let it decide what to do with the result. That’s how the shop can check for a newer tracking update than the one on Ada’s screen.

From LLM to agent
ReasonActObserveAda’s messagereplygoalanswerBRAINLLMKnowledgeToolsApproval
Problem
Ada wants to cancel her small espresso order. The shop needs her approval.
Solution
Extend the harness that runs the loop. It can now pause before a cancellation and save the request until Ada decides.
Like a person
A colleague marks a cancellation as pending so the next shift can pick it up.
Follow Ada’s message from the first call to the lookup of her grinder. The harness runs that loop. When the shop later adds a cancellation tool, the same loop can pause for Ada’s approval.

By chapter 4 we’ve written a small agent harness ourselves. When the model asks to look up Ada’s order, our code runs the lookup and puts the result in the next request. That’s how the model gets the tracking number it needs to ask the carrier. Our code also stops the run after at most eight model calls. In chapter 5 we give the same job to a library and see which decisions still belong to the shop.

Chapters 6 to 11 follow that harness as the shop gives it more responsibility. A lookup can fail. A cancellation waits for a yes, and we save the run so it can pick up where it left off. A script can play the model so a test can make it ask for 1077 every time. Chapter 12 looks at where agents stand today and what comes next.

In short

In short

  • Ada sets the goal. The model can choose a lookup based on what the previous one found.
  • The shop code owns the order record and checks for approval before a cancellation.
  • With a script we can replay the same request, approve it in one run and decline it in another.
  • We write the first four chapters by hand. From chapter 5 on, an agent SDK runs the loop.

Next

Chapter 1 goes back to Ada’s first question about the parcel with the grinder. What can the model tell her if all we send is her message?

Series

3 parts

An agent walks into a coffee shop

  1. 00Agent Smith doesn’t work hereYou are here
  2. 01One call later, where’s my coffee?
  3. 02Who told you that?

Written by

Phillipp Bertram

Software development and AI from Osnabrück

Ask my agent about this article

The article goes along as context. The answer opens in the chat.