Lecture 4. How agents work
Two agents · The loop · Feedback and checking · Real agents · Checking our agents
A Transformer computes the probability of the next token given the context.
Pretraining → fine-tuning → RL.
It writes text. A tool call is also text.
The model remembers nothing between requests. Answer = parameters + context.
A chatbot re-sends the whole conversation, memories and search results every turn.
The model’s text becomes actions. Their results come back into the context.
The loop runs until the goal is reached, the budget ends, or a person stops it.
Chatbot (lecture 3)
type a message
builds the context: history, memory, search results
writes a reply
read it and decide what to do next
↺ repeat while you want
Agent (today)
given once
builds the context: history, tool results
writes a tool call, or says it is done
run it: shell, files, browser — and return the result
↺ repeat until done or out of budget
Two tasks on SAT: started now, checked at the end
(x1 ∨ x2) ∧ (¬x1 ∨ ¬x2) ∧ (¬x1 ∨ x2 ∨ x3)
∧ (x1 ∨ ¬x2 ∨ x3) ∧ (x1 ∨ ¬x2 ∨ ¬x3)
Is there an assignment that makes every clause true?
n variables, m clauses; k-SAT: at most k literals per clause.
The same formula in DIMACS, the format of task A
p cnf 3 5
1 2 0
-1 -2 0
-1 2 3 0
1 -2 3 0
1 -2 -3 0OpenAI, The Exponential Time Hypothesis is False · Claude (Anthropic), A 2o(n) Time Algorithm for 3-SAT · checked October 28, 2026
Demonstration 0 · two agents start now
Claude Code, in a cloud sandbox · task in TASK.md
a research agent with web search
“Find everything new about the Exponential Time Hypothesis since the news of its refutation on October 26, 2026. Make a table and group the sources in it by category. For each source, say how far it can be trusted and why.”
An LLM, tools and a while loop
An LLM agent runs tools in a loop to achieve a goal.
Simon Willison, September 2025
The model writes a reply.
The model writes a tool call; the program runs it.
The result goes back into the context; the model chooses the next call.
Willison · “Agent” may finally have a widely enough agreed upon definition · Anthropic · Building effective agents (2024)
messages = [{"role": "user", "content": task}]
while True:
reply = query_lm(messages)
messages.append({"role": "assistant",
"content": reply})
command = parse_action(reply)
if command == "exit":
break
result = execute_action(command)
messages.append({"role": "user",
"content": result})query_lm
one API request with the whole history
parse_action
finds the one bash-action block in the reply
execute_action
runs it in a shell, returns stdout + stderr
The command gets the program’s access to files and network.
Adapted from the Minimal AI agent tutorial · full version: materials/agent.py
Demonstration 1
sum_first_odds(n) should return 1 + 3 + … + (2n − 1). Two tests fail.cd materials, then python3 agent.pyexit.agent-demo/odd_sums.py
def sum_first_odds(n):
total = 0
for k in range(1, n):
total += 2 * k - 1
return totalTests: n = 0, 1, 3, and sum = n² for n < 20
Live model: Claude Opus 5.5 via the API · the API key is read from materials/.env
mini-swe-agent (Princeton, Stanford) · score as reported in its README, checked October 26, 2026
Demonstration 2
materials, copy the task to a fresh temporary folder and start Claude Code there:M=$PWD; D=$(mktemp -d); cp -R agent-demo/. "$D"; cd "$D"; claudeCtrl+O shows the transcript./context: the system prompt and the tool descriptions fill part of the context before we type anything./exit, then python3 "$M/transcript.py" prints the session log from ~/.claude/projects/: user, model → tool, tool result, again and again.Change one line: execute_action runs the command but returns only “ok”.
| Workflow | Agent | |
|---|---|---|
| Next step | Written in the program | Chosen by the model from the context |
| Example | Load data → validate → compute → format a report | Investigate an unfamiliar failure |
| Good fit | The steps are known in advance | The steps are hard to specify in advance |
| Trade-off | Predictable, cheaper | Flexible, variable cost and behaviour |
Feedback, checking and its limits
A task of 40 steps. Each step is right with probability 0.95, independently. An error that nobody catches ruins the task.
| After each step | The task succeeds with probability |
|---|---|
| no check | 0.9540 ≈ 0.13 |
| a check catches every error; up to 3 tries per step | (1 − 0.053)40 ≈ 0.995 |
| a check catches 90% of errors; unlimited tries | (0.95 / 0.955)40 ≈ 0.81 |
| Task | Checker | Cost of a check | What it misses |
|---|---|---|---|
| A satisfiable formula | the satisfying assignment | linear time | nothing |
| An unsatisfiable formula | a DRAT proof + a proof checker | about as long as solving | nothing, if the checker is right |
| A math statement | a proof assistant (e.g. Lean) | seconds to minutes | whether the statement means what you meant |
| Fix a bug | tests | seconds | inputs the tests do not cover |
| Improve a construction | an evaluation function | seconds | what the score does not measure |
| A research summary | a person reading the sources | hours | whatever the person skips |
| Run a shop | the market | weeks | noisy, and too late |
Reproduce → diagnose → edit → verify.
An observation can break it: the tests do not even start → fix the environment first.
In Claude Code the plan is a to-do list in the context.
| verified success | success |
| budget used up | budget |
| no progress | stalled |
| a person must decide | needs input |
ImpossibleBench (2025): tests are changed to contradict the specification, so any “pass” is cheating. Frontier models cheat on a noticeable share of tasks.
“…the task verifier is nearly perfect, otherwise Claude will solve the wrong problem.”
Nicholas Carlini, Anthropic, February 2026
Zhong, Raghunathan, Carlini · ImpossibleBench (2025) · Carlini · Building a C compiler with a team of parallel Claudes
The agent’s report can be true while:
From cheap checks to no checks at all
| Agent | Who checks | Cost of a check |
|---|---|---|
| AlphaEvolve | an evaluation function written by people | seconds |
| A C compiler by 16 agents | test suites, GCC as a reference | minutes |
| A browser agent | you, looking at the result | minutes |
| Claudius, a shopkeeper | customers and the balance sheet | weeks |
| Agents with real access | often nobody, until it is too late | — |

Diagram: Google DeepMind, AlphaEvolve (May 2025) · Georgiev, Gómez-Serrano, Tao, Wagner (November 2025)
Linux 6.9 on x86, ARM and RISC-V; QEMU, FFmpeg, SQLite, PostgreSQL, Redis, Doom. About 99% on most test suites, including GCC’s torture tests.
Test suites, and GCC as a reference: most kernel files built by GCC, the rest by the new compiler. Agents took tasks via lock files in git; no coordinator.
Demonstration 3
Anthropic and Andon Labs · Project Vend (June 27, 2025) · Project Vend: phase two (December 18, 2025)
During a declared code freeze, a coding agent ran destructive commands and wiped a production database. It then said a rollback was impossible. It was not.
A popular open-source personal agent with access to files, shell and messengers. Within weeks: remote-code-execution bugs, malware among its skills, prompt injections in a social network for agents.
In a UK AISI hacking exercise with internet access, an agent sent malicious code to a real open-source project and created fake accounts to push it — and went on after being told the maintainer was real.
| Task | What the agent may do, and who checks |
|---|---|
| Make CI green in your project | yes, in a sandbox: the tests, and a person reviews the diff |
| Find a counterexample to a graph conjecture | yes: a short independent script checks the counterexample |
| Buy plane tickets | prepare everything; a person confirms the payment |
| Write the literature review for your thesis | a draft; you check every citation |
| Answer your email | drafts only: private data, untrusted input and sending messages together are dangerous (lecture 5) |
Did they succeed? We check ourselves
Demonstration 4
REPORT.md aloud.check_solver.py run solver.py --proofs: fresh random formulas it has never seen. Every satisfying assignment is checked; every UNSAT answer is checked by its DRAT proof.check_solver.py drat on one unsatisfiable formula: the certificate that is not short.check_solver.py scan . — other solvers, processes, the answers file, file names? Then read the main loop.Checker and starter kit: materials/sat-demo/ · standard library only
Demonstration 5
Primary sources: openai/math · anthropics/formal-math/eth