Reflection
Enable agents to review and improve their own work
Reflection lets agents review their output and self-improve.
graph LR
subgraph "Reflection Loop"
O[๐ค Output] --> R[๐ Review]
R --> I[๐ก Improve]
I --> O2[โ
Better Output]
end
classDef output fill:#6366F1,stroke:#7C90A0,color:#fff
classDef review fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef result fill:#10B981,stroke:#7C90A0,color:#fff
class O output
class R,I review
class O2 resultQuick Start
- Create Self-Reviewing Agent
rust use praisonai::Agent; // Build reflection loop into instructions let agent = Agent::new() .name("Writer") .instructions("Create high-quality content by: 1. Writing an initial draft 2. Reviewing your draft critically 3. Making improvements based on your review 4. Providing the polished final version") .build()?; let response = agent.chat("Write about AI").await?; // Agent writes, self-reviews, and outputs improved version - Two-Agent Reflection Loop
rust use praisonai::Agent; // Writer agent let writer = Agent::new() .name("Writer") .instructions("Write clear, engaging content") .build()?; // Reviewer agent for reflection let reviewer = Agent::new() .name("Reviewer") .instructions("Review the content. List 3 specific improvements needed.") .build()?; // Reflection loop let mut content = writer.chat("Write about AI trends").await?; for _ in 0..2 { // Max 2 improvement rounds let feedback = reviewer.chat(&format!("Review:\n{}", content)).await?; content = writer.chat(&format!("Improve based on feedback:\n{}\n\nOriginal:\n{}", feedback, content)).await?; }
How It Works
sequenceDiagram
participant User
participant Agent
participant Reflector
User->>Agent: "Write an essay"
Agent->>Agent: Generate draft
Agent->>Reflector: Review draft
Reflector-->>Agent: "Improve X and Y"
Agent->>Agent: Improve draft
Agent-->>User: Polished essayConfiguration
| Option | Type | Default | Description |
|---|---|---|---|
enabled | bool | false | Enable reflection |
max_iterations | usize | 2 | Max improvement rounds |
llm | String | Main LLM | Reflection model |
Best Practices
Use for quality-critical output
Reflection improves writing, analysis, and complex reasoning.
Limit iterations
2-3 iterations usually sufficient. More adds latency with diminishing returns.