01 · The LLM Call, Revisited as an Agent Primitive
We’ll start with an ordinary model call and look at the boundary between the model and the application:
An agent is built out of ordinary model calls.
There is no special “agent intelligence” hiding somewhere underneath.
At the bottom of everything we’re going to build over the next nine lessons is essentially this:
Python prepares context ↓Python calls model ↓Model returns something ↓Python decides what happens nextToday we’ll isolate that primitive and make sure the boundaries are completely clear.
1. Start with the smallest useful call
Section titled “1. Start with the smallest useful call”Using the OpenAI Python SDK:
The SDK is a Python library that prepares HTTP requests and gives us response objects. OpenAI() creates a client. If you choose to execute the API examples, it expects configured credentials, usually an OPENAI_API_KEY environment variable, and model usage has a cost. You need neither an account nor an API key to read the lessons.
The reviewed examples use Python 3.13.18, openai==3.55.1, and the documented gpt-5.5-2026-04-23 snapshot as of November 19, 2026. Pydantic 2.14.4 appears in the next lesson. Verification uses synthetic responses; the sample answers are illustrations, not live measurements. Model reference
from openai import OpenAI
client = OpenAI()
response = client.responses.create( model="gpt-5.5-2026-04-23", instructions=""" You are a software assistant. Give concise, practical answers. """, input="Explain what a database transaction is.")
print(response.output_text)instructions provides guidance for this request. input supplies the task or conversation items. response is a Python object representing what came back; response.output_text collects its text output. The raw response can also contain non-text items, which we’ll inspect in Lesson 3.
This opening example follows a successful response. A response can instead be refused, incomplete, or empty, and an API request can raise an exception. Later examples add explicit checks; a printed sentence alone never establishes that an external action happened.
Ignore agents for a moment.
What actually happened?
Your Python program created an HTTP request containing roughly:
MODEL: gpt-5.5-2026-04-23
INSTRUCTIONS: You are a software assistant. Give concise, practical answers.
INPUT: Explain what a database transaction is.The OpenAI server ran the model.
The server returned a response.
Your Python program received it.
That’s it.
2. The important boundary
Section titled “2. The important boundary”This distinction becomes critical once we start building agents.
The model can reason about what should happen.
Your Python application controls what actually happens.
For example, imagine asking:
response = client.responses.create( model="gpt-5.5-2026-04-23", input=""" A customer ordered an item that is out of stock. Decide what we should do. """)The model might answer:
Issue a refund and notify the customer.But nothing happened.
No refund occurred.
No email was sent.
No database changed.
The model produced information.
Your program would need to perform the actions.
Conceptually:
MODEL: "Issue refund."
PYTHON: refund_customer()That boundary is the foundation of tool calling, which we’ll reach in Lesson 3.
3. The model is not your program
Section titled “3. The model is not your program”This sounds obvious, but many confusing agent diagrams blur this distinction.
Suppose we write:
task = """Check whether invoice 4812 has been paid.If not, send the customer a reminder."""And send that to a model.
The model cannot magically inspect your database.
It cannot magically send the email.
It only knows what you provided in the request plus whatever capabilities the API explicitly exposes.
So this:
"Check invoice 4812"is merely language.
For it to become an actual software operation, something has to connect language to code.
Eventually we’ll build:
Model decides: check_invoice(4812)
Python executes: check_invoice(4812)
Python sends result back: unpaid
Model decides: send_reminder(4812)
Python executes: send_reminder(4812)That is where “agentic” behavior begins.
But every model interaction is still just another ordinary API call.
4. Inputs → model → outputs
Section titled “4. Inputs → model → outputs”A useful mental model is:
CONTEXT ↓ ┌──────────────┐ │ MODEL │ └──────────────┘ ↓ OUTPUTContext includes things such as:
instructionsuser requestconversation historytool definitionstool resultsretrieved documentsapplication stateThe model receives the context available for that call.
It produces an output based on that context.
This matters because the model does not somehow possess your application’s live state.
If your database says:
document.status = "approved"but you never tell the model that, the model does not know it.
5. Models do not automatically remember previous Python calls
Section titled “5. Models do not automatically remember previous Python calls”Consider this:
response1 = client.responses.create( model="gpt-5.5-2026-04-23", input="My favorite database is SQLite.")
response2 = client.responses.create( model="gpt-5.5-2026-04-23", input="What is my favorite database?")
print(response2.output_text)You should not design your application assuming that response2 inherently knows what happened in response1.
From the application’s point of view, those are separate calls.
You need to provide continuity.
One simple approach is explicitly carrying the earlier information:
response = client.responses.create( model="gpt-5.5-2026-04-23", input=""" Earlier the user said: My favorite database is SQLite.
Current question: What is my favorite database? """)Later we’ll handle state much more cleanly.
But the important architectural principle is:
Your application owns state.
Not the model.
That’s Lesson 5 in this series, and it becomes one of the biggest differences between a demo and a reliable agent.
6. Your first tiny “agent-shaped” program
Section titled “6. Your first tiny “agent-shaped” program”Let’s move one inch toward agents without actually building one yet.
Suppose we want a program that converts a vague request into a suggested next action.
from openai import OpenAI
client = OpenAI()
def decide_next_step(task: str) -> str: response = client.responses.create( model="gpt-5.5-2026-04-23", instructions=""" You help operate a software system.
Given a task, identify the single next action that should happen.
Do not perform the action. Only describe it. """, input=task, )
if response.status != "completed" or not response.output_text.strip(): raise RuntimeError("No completed text decision returned.")
return response.output_text
task = """A user uploaded a PDF.The file has already passed validation.It has not yet been analyzed."""
next_step = decide_next_step(task)
print(next_step)Possible output:
Run the document analysis process on the uploaded PDF.Notice the architecture:
Python owns task
Python sends task to model
Model decides next step
Python receives decisionThe small guard rejects an incomplete response or an absent text decision. It is not an assessment of whether the proposed action is correct. Lesson 4 handles response items explicitly, and Lesson 6 develops failure handling.
Right now Python just prints the decision.
Eventually Python could act on it.
That transition is the heart of agent engineering.
7. The model is the nondeterministic component
Section titled “7. The model is the nondeterministic component”Compare these two functions.
Normal Python
Section titled “Normal Python”def add(a, b): return a + bIf we run:
add(2, 3)we expect:
5Every time.
Now:
def decide_next_step(task): return call_model(task)Given the same input, the model might phrase or even reason about the answer differently.
For example:
Analyze the PDF.or:
Send the validated PDF to the document-analysis service.or:
Begin document analysis.All may mean the same thing.
This becomes a problem when Python needs to react to the result.
Python would hate this:
if response == "Analyze the PDF": ...because the model could respond with 500 semantically equivalent sentences.
Which brings us directly to our next lesson:
Structured outputs as contracts.
Instead of asking the model for arbitrary prose, we’ll eventually want something like:
{ "action": "analyze_document"}Now Python has something reliable to work with.
8. The three layers to keep separate
Section titled “8. The three layers to keep separate”From here forward, I want you to mentally separate three things.
Layer 1 — Deterministic application logic
Section titled “Layer 1 — Deterministic application logic”Your Python.
if document.status == "uploaded": ...Reliable, testable, explicit.
Layer 2 — Model reasoning
Section titled “Layer 2 — Model reasoning”The LLM.
Given this situation, which action makes sense?Flexible and probabilistic.
Layer 3 — External world
Section titled “Layer 3 — External world”Things your system can interact with:
databaseemailweb APIsfilesystembrowserpayment systemsearchEventually our architecture becomes:
┌──────────────┐ │ MODEL │ │ reasoning │ └──────┬───────┘ │ decision │ ↓ ┌──────────────┐ │ PYTHON │ │ control │ └──────┬───────┘ │ execution │ ↓ ┌────────────────────────────────┐ │ database / APIs / files / web │ └────────────────────────────────┘This picture will become increasingly important.
The model reasons.
Python controls.
Tools act.
9. Where “agents” actually emerge
Section titled “9. Where “agents” actually emerge”Suppose Python does this once:
ask modelprint answerThat’s an AI application.
Suppose Python does this:
ask model what to do ↓perform action ↓give result to model ↓ask what to do next ↓perform action ↓repeat until finishedNow we have something agent-shaped.
In pseudocode:
RECEIVE task
WHILE task is not finished
ASK model what to do
IF model requests an action EXECUTE action GIVE result back to model
ELSE RETURN answerThat WHILE loop is eventually going to become the center of this entire curriculum.
But notice what it contains:
ordinary model calls.
That’s the demystification I want you to keep.
10. A useful comparison
Section titled “10. A useful comparison”Traditional program:
Developer determines sequence beforehand.
Step AStep BStep CStep DAgentic program:
Developer determines boundaries and capabilities.
Model decides which permitted step should happen next.
Step ?Step ?Step ?The developer hasn’t disappeared.
The developer has moved up one level.
Instead of specifying every execution path, you specify:
what the model knowswhat the model may dowhat tools existwhat limits existwhat counts as finishedwhat happens when things failThat’s why agent engineering is still software engineering.
11. Short exercise
Section titled “11. Short exercise”No coding necessary.
Imagine we’re building an agent that handles incoming support requests.
Requirement:
Read the customer’s message, look up their account if necessary, and either answer the question or escalate it to a human.
Try to separate the responsibilities mentally.
A good decomposition would be something like:
PYTHON: receive support request
MODEL: understand customer's intent
MODEL: decide whether account information is required
PYTHON: if requested, retrieve account information
MODEL: examine account information
MODEL: decide whether it can answer safely
PYTHON: if answer: return answer
PYTHON: if escalation: create human-support ticketThe important question isn’t:
How would I code the agent?
It’s:
Which decisions belong to the model, and which actions/control belong to normal software?
That’s the habit we’re developing.
What breaks in production?
Section titled “What breaks in production?”This tiny example:
response = client.responses.create(...)looks almost ridiculously easy.
Real systems fail around it.
1. The model returns something unexpected
Section titled “1. The model returns something unexpected”You expected:
Analyze document.It returns three paragraphs instead.
Later we’ll fix this with structured outputs.
2. The API request fails
Section titled “2. The API request fails”Network timeout.
Rate limit.
Temporary service failure.
Your application needs retry/error behavior.
That’s Lesson 6.
3. The model chooses a bad action
Section titled “3. The model chooses a bad action”The model might misunderstand the situation.
You cannot simply assume:
model said ittherefore execute itSome actions need validation or human approval.
That’s Lesson 7.
4. Context becomes huge
Section titled “4. Context becomes huge”If you keep sending everything that ever happened:
message 1message 2message 3...message 10,000cost and latency increase, and useful context gets buried.
That’s part of Lesson 5.
5. The system loops forever
Section titled “5. The system loops forever”Eventually we’ll build:
while not finished: ...What if the model never decides it’s finished?
You need:
MAX_STEPS = 10Agent autonomy should always have boundaries.
6. It looks great in one demo but fails unpredictably
Section titled “6. It looks great in one demo but fails unpredictably”This is one of the biggest traps.
You run the agent once:
perfect resultand think:
It works.
Then users give it 500 different inputs.
That’s why we’ll eventually build evals rather than trusting impressive demos.
Lesson 8.
The takeaway
Section titled “The takeaway”Today the most important thing to internalize is:
An agent is not a magical new kind of model.
It is software that repeatedly uses a modelas one component in a controlled system.Or even more compactly:
MODEL = reasoning
PYTHON = control
TOOLS = actions
STATE = memory
LOOP = agencyWe haven’t built any of those abstractions yet.
Good.
Over the next lessons, we’ll construct them one at a time with normal Python so you can see exactly where each piece comes from.
Next: Structured Outputs as Contracts
Section titled “Next: Structured Outputs as Contracts”Our current model can respond with essentially arbitrary text:
"Analyze the PDF."
"Begin analysis."
"I recommend analyzing the document next."Humans understand that.
Python does not.
Next time we’ll turn fuzzy model output into reliable application data:
{ "action": "analyze_document", "reason": "The document has passed validation."}That seemingly small change is one of the foundations of reliable AI systems.