AI Agent Design Patterns: ReAct, CodeAct & More | Stanford CS329Z Lecture 6 with Michael Ryan
Stanford Online
Patterns and scaffolds 0:05
Design patterns are common in software engineering, and the same idea applies to agent systems. Patterns can guide how you build, but they are half-baked and you still have to adapt them to your own setting. The lecture focuses on the design choices you face when you build agents, on patterns for workflows and agents, and on a case study of the Pie agent harness.
Workflows and agents 3:30
A workflow keeps control flow in the program code. An agent gives the LLM the control flow, so it decides what to do next and which tools to call. That makes workflows more predictable and easier to evaluate, while agents are more flexible and adaptable but harder to optimize. A support ticket can be handled as a workflow when you just classify it and reply, or as an agent when you need to investigate and solve the problem.
Storm workflow 14:32
Storm turns a topic into a full article with citations. It starts by finding related writing and pulling out perspectives such as seismologists, geologists, politicians, and city residents. Each perspective then asks questions, searches for answers, and builds a conversation record. That record helps form an outline, while a second path goes straight from topic to an initial outline. The system then writes the article from the outline and collected references.
Archon techniques 25:01
Archon searches for a workflow that fits a benchmark and budget. It mixes off-the-shelf language models with steps like generator, fuser, critic, ranker, verifier, and unit test generator. A generator gives a first answer. A fuser combines several answers into one. A critic lists strengths and weaknesses. A ranker orders options. A verifier checks whether an answer is correct and can trigger regeneration. The system tries candidate workflows and uses the results to improve them.
Searchable math workflow 29:00
The lecture walks through an architecture search result for math problems. It starts with several models generating five samples each, then has Claude critique all twenty answers, rank them, and group them into fused chunks. A verifier, GPT-4o, checks the responses and corrects them, and a final fuser produces one output. The point is that the search can discover a workflow that is more useful than a single answer or a simple self-critique loop.
Reasoning and acting 34:02
Agents are then framed as an LLM that interacts with an environment, gets feedback, and decides when to stop. The first pattern is ReAct, which combines thought and action. A question about the Apple remote shows the difference between plain prompting, chain of thought, tool use alone, and a loop where the model thinks, searches, revises, and then answers correctly. The main idea is to reason before taking actions.
Critics and tool use 43:30
The critic paper pushes beyond plain self-reflection. It gives the verifier tools so it can search and call functions, and that makes it more agentic. The result is stronger than prompting the model to reflect on its own. An external verifier can help more than self-reflection alone when the model needs to check its reasoning against outside steps.
Code and planning 45:31
CodeAct treats code as a better way to take actions. Instead of sending each step as JSON or text, the model writes a small program that calls tools, loops over countries, and uses functions like min. It gets higher success, fewer turns, and often less latency. ReWOO and LLM compiler take a similar view: plan first, then execute a workflow or graph, with re-planning if the task fails.
Preserving context continuity 58:00
Context changes should keep requirements, goals, constraints, and progress intact. If you snip away history carelessly, the agent can drift into behavior you did not expect. Keeping the KV cache also matters, because reshuffling context can invalidate it and slow inference. The main context patterns here are persistent event log, memory offloading, compaction, observation masking, and context isolation.
Isolation and Pi 1:07:30
A persistent event log records every user message, action, and observation, then rebuilds LLM input from that log each time. Memory offloading stores facts in files or memory for later retrieval. Compaction summarizes long traces, while observation masking trims or deletes bulky outputs. Context isolation uses subagents or progressive disclosure through skill files. Pi is then introduced as a minimal agent harness with only read, bash, edit, and write enabled by default.
Pi’s minimal harness 1:13:00
Pi uses a very small set of tools: bash, read, write, and edit. Its agent loop is ReAct, with reasoning before JSON tool calls. Context is stored as an event log and can branch back to earlier points, then compact older turns into summaries. It also runs with no built-in permission prompts or safety checks.
AI-generated summary. It can be wrong or incomplete - check anything that matters against the original.

