Skip to content

Codex Agentic Patterns

Learn to build production AI agents through real-world patterns extracted from OpenAI Codex CLI.

This guide bridges theory and practice by analyzing 100,000+ lines of production Rust code from OpenAI's battle-tested agent system. Each pattern includes Python implementations, real-world examples, and hands-on exercises you can run immediately.

Chapters

Chapter 1 - Prompt Chaining
Breaking complex tasks into sequential, manageable steps

Chapter 2 - Routing
Dynamically directing workflow based on intent and context

Chapter 3 - Parallelization
Executing independent operations concurrently for better performance

Chapter 4 - Tool Use
Extending agent capabilities through external system integration

Chapter 5 - Planning
Goal decomposition and step-by-step execution strategies

Chapter 6 - Reflection
Self-assessment and iterative improvement patterns

Chapter 7 - Memory Management
Conversation persistence and state handling

Chapter 8 - MCP Integration
Model Context Protocol for extensible tool systems

Chapter 9 - Exception Handling
Retry logic and graceful error recovery

Chapter 10 - Human-in-the-Loop
Approval workflows and user control mechanisms

Chapter 11 - Knowledge Retrieval
RAG systems and information retrieval patterns

Chapter 12 - Reasoning
Advanced reasoning and chain-of-thought techniques

Chapter 13 - Sandbox Escalation
Multi-stage execution with security and retry mechanisms

Chapter 14 - Turn Diff Tracking
Git-style change tracking across agent turns

Chapter 15 - Rollout System
Session recording, replay, and debugging workflows

Chapter 16 - Inter-Agent Communication
Agent-to-agent messaging and coordination patterns

Chapter 17 - Evaluation & Monitoring
Metrics collection, performance tracking, and observability

Complete Agent Example
Production-ready implementation combining multiple patterns


Grounded in OpenAI Codex CLI • Built with Cursor