> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Reflection

> Enable agents to review and improve their own work

Reflection lets agents review their output and self-improve.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 result
```

## Quick Start

<Steps>
  <Step title="Create Self-Reviewing Agent">
    ```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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
    ```
  </Step>

  <Step title="Two-Agent Reflection Loop">
    ```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    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?;
    }
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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 essay
```

***

## 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

<AccordionGroup>
  <Accordion title="Use for quality-critical output">
    Reflection improves writing, analysis, and complex reasoning.
  </Accordion>

  <Accordion title="Limit iterations">
    2-3 iterations usually sufficient. More adds latency with diminishing returns.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Planning" icon="list-check" href="/docs/rust/planning">
    Think before acting
  </Card>

  <Card title="Evaluation" icon="chart-bar" href="/docs/rust/evaluation">
    Measure quality
  </Card>
</CardGroup>
