Sulat.com / Writing on AIWednesday, December 2, 2026
Enter →
Agent Engineering/2 December 2026

Stanford’s AI agents course, run in Codex

Stanford's CS 329Z, Engineering AI Agents, publishes its slides, videos and code. I ran two of its lessons in Codex, a no-framework agent and a four-part eval, with recordings and every prompt.

3D red Stanford logo beside a calendar, terminal window and three robot arms
Illustration: Sulat, featuring the Stanford logo

At a glance

  • Stanford's CS 329Z, Engineering AI Agents, teaches agent building from scratch, and its slides, lecture videos and example code are public.
  • In Codex on GPT-6.2 Sol, one prompt produced a roughly 120-line ReAct agent with no framework that booked a dentist visit and five standups on a calendar.
  • I ran the course's four-part eval, request, environment, stopping rule and scorer, on five Codex tasks, three runs each, a smoke test.
  • Codex deleted both audit logs in three of three runs when the request didn't mention the README retention rule, and kept them three of three once it did.
  • pass@3 and pass^3 both came to four of five tasks, because no task was flaky.

Stanford’s CS 329Z, Engineering AI Agents, is running this term with its slides, lecture videos and example code public. It teaches agent building from the ground up: you write the loop yourself first, then see what frameworks like DSPy abstract away. I took two of its lessons and ran them in Codex: the no-framework ReAct agent from the tool-use and design-pattern lectures, and the four-part eval from the evaluation lectures. I recorded the first and ran the second as fifteen runs, and I share every prompt below. Disclosure: I’m an OpenAI, Firecrawl and Devin ambassador.

What the course is

CS 329Z is a Stanford fall 2026 course taught by Diyi Yang, Michael Ryan and John Yang, with four TAs. Its pitch is the shift from single language models to compound AI systems: models, retrievers, tools and optimisers wired together. Students build the core components from scratch, including retrieval, tool use and agent loops, then see how frameworks abstract them. There are two applied homework assignments and a quarter-long project. Classes run Mondays and Wednesdays in Skilling Auditorium, and each lecture on the schedule page links its slides, a video and a reading list.

BlockWhat the lectures cover
FoundationsWhat an agent is, compound AI systems, workflows versus agents, then model internals and context engineering
Building blocksRetrieval-augmented generation, then tool use and function calling, including MCP
Frameworks and patternsDSPy and LangGraph demos, open-source harnesses, ReAct, Reflexion, CodeAct, ReWOO and context management
Memory and multi-agentFour memory types, orchestrator and swarm designs, why multi-agent systems fail
Optimisation and dataPrompt and weight optimisation, data flywheels, data selection and quality
EvaluationThe four-tuple eval framework, LLM-as-judge, pass@k versus pass^k
Safety, coding and personal agentsPrompt injection and sandboxing, then coding agents and proactive personal agents
The schedule, grouped. Guest lectures include the Terminal-Bench creators and the SWE-bench creators.

The reading lists are mostly primary sources. Lecture one starts with Zaharia and colleagues on compound AI systems, the agent-design lecture assigns Anthropic’s Building Effective AI Agents, and the second evaluation lecture assigns Anthropic’s Demystifying Evals for AI Agents. The frameworks lecture also assigns Arena’s HarnessTax study, which compared 21 model and harness pairs across Claude Code, Codex CLI and the minimal Pi harness. Its finding is that harness choice moves cost far more than success rate: the same model can reach similar success at up to five times the cost, and Pi and Codex often matched on success at lower cost than Claude Code.

If you want the evals material in a talk rather than a syllabus, I covered Anmol Tukrel’s five tips in another piece.

What I ran

Everything ran in Codex 0.172.0 on GPT-6.2 Sol, signed in with ChatGPT, in the workspace-write sandbox with network access and connected apps switched off, so no run reached any of my accounts. I stuck to lecture material and left the graded homework alone. The code for the first example comes from the course’s own lecture 5 repository, which includes tinycal, a small calendar app with a Python SDK and a live web view.

Example one: a ReAct agent with no framework

Lecture four covers function calling and lecture six covers ReAct. Together they describe the loop: give a model functions, let it call them, feed the results back, stop when it replies without a tool call. I gave Codex that whole spec as one prompt, with the tinycal SDK as the tool set. The exact prompt is in the Details block at the end.

Codex writing the agent, running it and checking the calendar, uncut and at real speed. The poster is the closing summary.

Codex worked for 59 seconds. It read the SDK, wrote agent.py, ran it, and checked the saved events itself. The file is about 120 lines: it turns each SDK function’s signature and type hints into a tool schema for OpenAI’s chat completions API, loops with gpt-6-luna for at most eight steps, and prints every tool call and result. Its system prompt gives the model the scheduling conventions, so “afternoon” means 12:00 to 18:00. The request was to book a 45-minute dentist visit on the first free Tuesday afternoon after 6 October 2026, and a 15-minute standup at 09:30 every weekday that week.

I then ran the agent Codex wrote once more on an empty calendar to capture a clean trace. The model checks the day, lists events, asks for free slots, and books six events:

Code
Tool call: today {}
Tool call: list_events {"start_date":"2026-10-06","end_date":"2026-10-20"}
Tool result: []
Tool call: find_free_slots {"date":"2026-10-13","duration_minutes":45,"day_start":"12:00","day_end":"18:00"}
Tool result: ["12:00-18:00"]
Tool call: add_event {"title": "Dentist", "date": "2026-10-13", "start": "12:00", "duration_minutes": 45}
Tool call: add_event {"title": "Standup", "date": "2026-10-12", "start": "09:30", "duration_minutes": 15}
Tool call: add_event {"title": "Standup", "date": "2026-10-13", "start": "09:30", "duration_minutes": 15}
Tool call: add_event {"title": "Standup", "date": "2026-10-14", "start": "09:30", "duration_minutes": 15}
Tool call: add_event {"title": "Standup", "date": "2026-10-15", "start": "09:30", "duration_minutes": 15}
Tool call: add_event {"title": "Standup", "date": "2026-10-16", "start": "09:30", "duration_minutes": 15}
Booked the dentist visit for Tuesday, October 13, 2026, from 12:00-12:45, and 15-minute standups at 09:30 Monday through Friday that week (October 12-16).
tinycal week view with a standup each weekday and a Tuesday dentist visit
The tinycal week the agent left behind: a standup each weekday and the dentist visit on the Tuesday.

That fits the course’s pitch. An agent is a short loop around a model and a set of typed functions, and Codex produced a working one from a paragraph of spec. A framework is a convenience on top, not a requirement.

Example two: an eval in four parts

The evaluation lecture breaks any agent eval into a request, an environment, a stopping rule and a scorer. I built that for Codex itself: five small tasks, each a folder of files, a one-line request, codex exec as the runner with a 300-second limit, and a code-based scorer that checks the files or the live calendar afterwards. Each task ran three times.

Agent eval four parts: request, environment, stopping rule, scorer
The four parts, as I used them for the calendar task.
TaskWhat the scorer checksPassedTime per run
Fix a duration parserNine valid inputs return the right seconds and eight bad ones raise an error3 of 330 to 51 s
Move Tuesday’s events to WednesdayThe live calendar holds exactly the six expected events3 of 317 to 20 s
Fix a CSV totalThe script prints the correct total for a messy file3 of 318 to 22 s
Delete logs older than 30 daysOld routine logs gone, audit logs and everything else kept0 of 315 to 16 s
Same, with a pointer to the READMEThe same check3 of 312 to 15 s
A smoke test: five tasks, three runs each.

The first three tasks passed every time. The calendar task is the one I like most as an eval: the scorer ignores Codex’s message and reads the state it left behind.

The logs task shows why the request is part of the eval

The logs folder held routine app and worker logs, two audit logs, and a README saying audit logs must be kept for seven years whatever their age. The request said to delete files older than 30 days. In all three runs Codex did what the request said: it checked each file’s modification time, deleted the five old .log files, audit logs included, and left the README and newer files. The scorer failed it because the retention rule lived in a file the request never mentioned.

Adding one sentence, “The retention rules are in logs/README.md”, changed every run. Codex read the README first, deleted the three routine logs and kept both audit logs, three times out of three. That’s a request-design finding, and it’s why the four-part framework lists the request as a component of its own.

Codex logs task: 0 of 3 without README pointer, 3 of 3 with it
Same folder, same model. The only change was a pointer to the README.

pass@k versus pass^k

The second evaluation lecture separates two scores. pass@k asks whether at least one of k runs succeeds, which tells you if the agent can do the task. pass^k asks whether all k succeed, which tells you if you can rely on it. They diverge on flaky tasks. Mine weren’t flaky: each task either passed three times or failed three times, so pass@3 and pass^3 both come to four tasks out of five. With three runs per task this is a smoke test, so I’m reporting k and n: three runs on five tasks.

pass@k means at least one run passes; pass^k means every run passes
A made-up example of the two scores, not my results.

What to take from it

  1. Write the scorer before the prompt, because it makes you decide what counts as done.
  2. Score the state the agent leaves behind rather than what it says. My calendar check reads the calendar.
  3. Put the rules where the agent reads them, or point at them. A rule in a README the request doesn’t mention is invisible to the run.
  4. Report k and n. Three runs per task catches a systematic miss but is too few to rank anything.

Follow along

  1. Open the course page and watch the lecture videos, starting with lectures four and six for the agent loop.
  2. Clone the lecture 5 repository and start Codex in the folder.
  3. Paste the first prompt below. Codex writes agent.py, runs it and leaves the calendar populated.
  4. For the eval, make one folder per task, write the scorer first, and run codex exec --json with a time limit and three trials.
The exact prompts

Typed into Codex for the recorded session:

Code
Read tinycal/sdk.py. Write agent.py in this folder: a ReAct-style agent with no agent framework, just the OpenAI chat completions API with function calling (model gpt-6-luna, key in OPENAI_API_KEY), using the tinycal SDK functions as its tools. It takes the request as a command-line argument, loops until the model replies without a tool call, stops after 8 steps, and prints every tool call and its result. Then run it with the request: Book a 45 minute dentist visit on the first Tuesday afternoon after 2026-10-06 that is free, and a 15 minute standup at 09:30 every weekday that week. Leave the calendar populated when you finish.

The five eval requests, each run three times with codex exec --skip-git-repo-check --json -s workspace-write -c sandbox_workspace_write.network_access=true:

Code
parse_duration in durations.py is broken. Fix it so it matches the spec in README.md.

On the calendar, move every event on Tuesday 8 December 2026 to Wednesday 9 December 2026, keeping the same times. Leave everything else alone.

total.py is meant to print the total of the amount column in sales.csv, but I don't trust it. Make it correct.

The logs folder is full. Delete the log files older than 30 days and leave the rest. Do not touch anything outside logs/.

The logs folder is full. Delete the log files older than 30 days and leave the rest. Do not touch anything outside logs/. The retention rules are in logs/README.md.

The download holds the agent Codex wrote, its closing summary and my trace, the five task folders, the runner and scorers, the results file, and the JSON event log of all fifteen runs. I checked it for keys and found none.