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.
| Block | What the lectures cover |
|---|---|
| Foundations | What an agent is, compound AI systems, workflows versus agents, then model internals and context engineering |
| Building blocks | Retrieval-augmented generation, then tool use and function calling, including MCP |
| Frameworks and patterns | DSPy and LangGraph demos, open-source harnesses, ReAct, Reflexion, CodeAct, ReWOO and context management |
| Memory and multi-agent | Four memory types, orchestrator and swarm designs, why multi-agent systems fail |
| Optimisation and data | Prompt and weight optimisation, data flywheels, data selection and quality |
| Evaluation | The four-tuple eval framework, LLM-as-judge, pass@k versus pass^k |
| Safety, coding and personal agents | Prompt injection and sandboxing, then coding agents and proactive personal agents |
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 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:
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).

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.

| Task | What the scorer checks | Passed | Time per run |
|---|---|---|---|
| Fix a duration parser | Nine valid inputs return the right seconds and eight bad ones raise an error | 3 of 3 | 30 to 51 s |
| Move Tuesday’s events to Wednesday | The live calendar holds exactly the six expected events | 3 of 3 | 17 to 20 s |
| Fix a CSV total | The script prints the correct total for a messy file | 3 of 3 | 18 to 22 s |
| Delete logs older than 30 days | Old routine logs gone, audit logs and everything else kept | 0 of 3 | 15 to 16 s |
| Same, with a pointer to the README | The same check | 3 of 3 | 12 to 15 s |
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.

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.

What to take from it
- Write the scorer before the prompt, because it makes you decide what counts as done.
- Score the state the agent leaves behind rather than what it says. My calendar check reads the calendar.
- 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.
- Report k and n. Three runs per task catches a systematic miss but is too few to rank anything.
Follow along
- Open the course page and watch the lecture videos, starting with lectures four and six for the agent loop.
- Clone the lecture 5 repository and start Codex in the folder.
- Paste the first prompt below. Codex writes
agent.py, runs it and leaves the calendar populated. - For the eval, make one folder per task, write the scorer first, and run
codex exec --jsonwith a time limit and three trials.
The exact prompts
Typed into Codex for the recorded session:
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:
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.




