Tool calling + a loop = an agent. Strip it to pseudocode:
# Pseudocode — not real Python, just the shape
state = initial_input
while not done:
decision = LLM(state) # next tool? or final answer?
if decision is FINAL_ANSWER:
done = True
else:
result = execute_tool(decision)
state = state + result # accumulate context
return state.final_answerSo an agent is a loop where the LLM decides each iteration whether to call another tool or to finish.
Yes. Three roles: a state (everything seen so far), a deciding LLM (picks tool or answers), and an executor (runs the tool, feeds the result back). The loop terminator is the LLM saying "FINAL_ANSWER" — usually expressed in the protocol as "no more tool calls, here's the answer".
Pydantic-AI's run_sync already loops internally — so I've been using agents since week 1?
Half-right. run_sync runs the loop for you up to its built-in iteration limit. What week 3 makes explicit is: what's happening inside that loop, how to inspect it, and how to write the same loop yourself when the framework doesn't fit. The mental model first; tomorrow we write one in plain Python.
What's the loop terminator then, formally?
"The model's most recent response is a final answer (no tool calls left)". That's the universal terminator. Some agents add safety nets — a max-iteration cap, a quota cap. Both are good. Loops without terminators are bugs.
An agent is LLM + tools + loop.
┌─ initial input ──┐
│ ↓
│ [LLM call]
│ / \
│ tool call? final answer?
│ ↓ ↓
│ [execute tool] return
│ ↓
│ accumulate result into state
│ │
└─────────┘
The loop:
| Property | Why it matters |
|---|---|
| Loop | Multiple tool calls can happen in sequence |
| State accumulation | Each tool result becomes context for the next LLM call |
| Self-termination | The LLM decides when it's done, not your code |
A single tool call (week 1) is the agent loop running once. Multi-step tool calling (L4) is the loop running 2-3 times. A real agent might run 5+ iterations on a complex task.
Universal: the LLM's response contains no tool calls — i.e., it produced a plain text final answer.
Safety nets:
Without these, a confused LLM can loop forever calling tools that don't help. Always add at least max-iterations.
Week 3's lessons walk through these one at a time. Today: just identify what the loop terminator is.
Pure Python — no LLM call. Read the pseudocode in the prompt. Print the loop terminator. Concept lesson.
Tool calling + a loop = an agent. Strip it to pseudocode:
# Pseudocode — not real Python, just the shape
state = initial_input
while not done:
decision = LLM(state) # next tool? or final answer?
if decision is FINAL_ANSWER:
done = True
else:
result = execute_tool(decision)
state = state + result # accumulate context
return state.final_answerSo an agent is a loop where the LLM decides each iteration whether to call another tool or to finish.
Yes. Three roles: a state (everything seen so far), a deciding LLM (picks tool or answers), and an executor (runs the tool, feeds the result back). The loop terminator is the LLM saying "FINAL_ANSWER" — usually expressed in the protocol as "no more tool calls, here's the answer".
Pydantic-AI's run_sync already loops internally — so I've been using agents since week 1?
Half-right. run_sync runs the loop for you up to its built-in iteration limit. What week 3 makes explicit is: what's happening inside that loop, how to inspect it, and how to write the same loop yourself when the framework doesn't fit. The mental model first; tomorrow we write one in plain Python.
What's the loop terminator then, formally?
"The model's most recent response is a final answer (no tool calls left)". That's the universal terminator. Some agents add safety nets — a max-iteration cap, a quota cap. Both are good. Loops without terminators are bugs.
An agent is LLM + tools + loop.
┌─ initial input ──┐
│ ↓
│ [LLM call]
│ / \
│ tool call? final answer?
│ ↓ ↓
│ [execute tool] return
│ ↓
│ accumulate result into state
│ │
└─────────┘
The loop:
| Property | Why it matters |
|---|---|
| Loop | Multiple tool calls can happen in sequence |
| State accumulation | Each tool result becomes context for the next LLM call |
| Self-termination | The LLM decides when it's done, not your code |
A single tool call (week 1) is the agent loop running once. Multi-step tool calling (L4) is the loop running 2-3 times. A real agent might run 5+ iterations on a complex task.
Universal: the LLM's response contains no tool calls — i.e., it produced a plain text final answer.
Safety nets:
Without these, a confused LLM can loop forever calling tools that don't help. Always add at least max-iterations.
Week 3's lessons walk through these one at a time. Today: just identify what the loop terminator is.
Pure Python — no LLM call. Read the pseudocode in the prompt. Print the loop terminator. Concept lesson.
Create a free account to get started. Paid plans unlock all tracks.