Reflection
Enable agents to review and improve their own work
Reflection lets agents review their output and self-improve.
Quick 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
Configuration
| 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.