Stanford Online

AI Agent Design Patterns: ReAct, CodeAct & More | Stanford CS329Z Lecture 6 with Michael Ryan

Published 2026-11-14 · Duration 1:16:51

Summary

This lecture provides a deep dive into advanced design patterns for building AI agents and complex workflows. It contrasts traditional workflows (where control flow resides in program code) with agents (where control flow is managed by the LLM). Key agent patterns include ReAct (Reasoning-Acting loop), Reflection (learning from past experience), CodeAct (using code generation for actions), and ReWOO (planning before execution). For context management, the discussion covers techniques like Persistent Event Logging, Observation Masking, and Context Isolation (via subagents), culminating in a review of the minimalist Pi agent harness.

Download summary

Key takeaways

  1. Workflows vs. Agents 1:47

    Workflows are ideal for tasks with clear, repeatable structure (control flow in code), while agents are better suited for tasks requiring flexible, adaptive decision-making (control flow in the LLM).

  2. CodeAct Pattern 21:22

    Using code generation as the action format (CodeAct) is superior to JSON or text tool calls because it is more accurate, more efficient, and accomplishes tasks in fewer turns.

  3. ReWOO (Plan then Execute) 24:25

    Instead of iterative reasoning (ReAct), generating a full plan (Directed Acyclic Graph) first, and then executing the steps, is a powerful pattern that reduces token usage and latency.

  4. Context Management Strategies 37:55

    Effective context management involves techniques like Persistent Event Logging (preserving all actions/observations) and Observation Masking (condensing observations instead of summarizing the entire history) to prevent context window bloat.

More digests on Agent Design Patterns

Technical details

  • Workflow Design Patterns (Anthropic Taxonomy) 200s

    Five patterns include: Prompt Chaining (decomposing tasks into sequential LLM calls), Routing (dispatching input to specialized models/workflows), Parallelization (dividing independent work across threads), Orchestrator Workers (dynamically dispatching subtasks), and Evaluator Optimizer (using an LLM to review and provide feedback to a generator in a loop).

  • Agent Design Patterns 200s

    1. ReAct: Combines Chain of Thought (reasoning) and Actions (tool calls). 2. Reflection: Improves performance by learning from long-term experience and trajectories. 3. CodeAct: Uses code generation for actions. 4. ReWOO: Plans the entire sequence of actions (DAG) before execution.

  • Context Management Patterns 2275s

    1. Persistent Event Log: Records every action, observation, and response to allow reconstruction of the context. 2. Memory Offloading: Storing facts (e.g., user details) externally and retrieving them via tool calls (RAG). 3. Compaction: Summarizing long context segments. 4. Observation Masking: Programmatically condensing or truncating observations rather than relying solely on summarization. 5. Context Isolation: Using subagents or Progressive Disclosure (skill files) to limit the scope of context.

  • Pi Agent Harness 3900s

    Pi is a minimalist agent harness designed to be adapted to custom workflows. It features built-in context management via event logs, progressive disclosure, and compaction, but lacks built-in safeguards (e.g., permission checks).

Mentioned resources

Channel & topics

Watch on YouTube · Back to latest

This independent, AI-assisted summary is provided for commentary and informational purposes. It may contain errors or omit important context. Please watch the original video for the creator's complete presentation. Video, thumbnail, and related copyrights belong to their respective owners.