Agent Control Patterns — Part 3: Reflexion — When Review Triggers Research
Summary
The Reflexion pattern extends the Reflection technique for large language models by integrating external research to improve factual accuracy, not just clarity or reasoning. While Reflection improves answers using only the model's internal knowledge, Reflexion introduces a structured workflow: Draft → Self-Critique → Generate Search Queries → Run Tools → Revise Using Evidence → Stop. This process is enabled by a structured `DraftOutput` Pydantic model, which forces the model to produce an initial answer, a self-critique identifying gaps, and specific search queries. These queries are then executed by an external tool, like a web search API, and the retrieved evidence is used to inform an evidence-based revision, resulting in a `FinalOutput` that includes references. This multi-step, controlled approach, implemented via separate nodes in a graph, allows the system to correct outdated or factually incorrect information, especially for time-sensitive questions or tasks requiring verified claims.
Key takeaway
For AI Engineers building systems that require high factual accuracy or deal with time-sensitive information, adopting the Reflexion pattern is crucial. This approach allows your models to move beyond internal reasoning by programmatically triggering external research and incorporating new evidence. Implement structured output formats for drafts and revisions, and integrate reliable search tools to ensure claims are verifiable and up-to-date, thereby enhancing the trustworthiness of your AI applications.
Key insights
Reflexion enhances LLM factual accuracy by integrating external research into a structured self-correction loop.
Principles
- Separate generation from evaluation.
- Structure critique to trigger research.
- Evidence-based revision improves accuracy.
Method
The Reflexion workflow involves drafting, self-critiquing to generate search queries, executing queries via external tools, and then revising the answer using the retrieved evidence, often with iteration limits.
In practice
- Use Pydantic models for structured LLM outputs.
- Integrate web search APIs for external evidence.
- Implement iteration limits to prevent loops.
Topics
- Reflexion AI Pattern
- External Knowledge Integration
- Evidence-Based Revision
- AI Workflow Orchestration
- ReAct Pattern
Best for: Machine Learning Engineer, AI Engineer, Research Scientist
Related on AIssential
Editorial summary, takeaway, and curation by AIssential. Original article published by Towards AI - Medium.