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

# Self Reflection

> Let agents evaluate and refine their own responses before delivery

Enable `reflection=True` on an agent and it critiques its own answer before returning — improving quality within the same task.

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
from praisonaiagents import Agent

agent = Agent(
    name="Analyst",
    instructions="Provide thorough, accurate analysis.",
    reflection=True,
)
agent.start("Summarise recent AI safety developments")
```

The user asks a question; the agent drafts an answer, reflects on quality, then returns the improved response.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph LR
    subgraph "Self-Reflection Loop"
        In[Input] --> Agent[Agent]
        Agent --> Draft[Draft answer]
        Draft --> Reflect{Reflect}
        Reflect -->|improve| Agent
        Reflect -->|satisfied| Out[Output]
    end

    classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
    classDef agent fill:#8B0000,stroke:#7C90A0,color:#fff
    classDef gate fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef output fill:#10B981,stroke:#7C90A0,color:#fff

    class In input
    class Agent,Draft agent
    class Reflect gate
    class Out output
```

## Quick Start

<Steps>
  <Step title="Simple Usage">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent

    agent = Agent(
        name="Analyst",
        instructions="Provide thorough, accurate analysis.",
        reflection=True,
    )
    agent.start("Summarise recent AI safety developments")
    ```
  </Step>

  <Step title="With Configuration">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonaiagents import Agent, ReflectionConfig

    agent = Agent(
        name="Analyst",
        instructions="Provide thorough, accurate analysis.",
        reflection=ReflectionConfig(
            min_iterations=1,
            max_iterations=3,
            llm="gpt-4o",
            prompt="Check accuracy, completeness, and clarity.",
        ),
    )
    agent.start("Summarise recent AI safety developments")
    ```
  </Step>
</Steps>

***

## How It Works

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
sequenceDiagram
    participant U as User
    participant A as Agent
    participant R as Reflection pass

    U->>A: Prompt
    A->>A: Generate draft
    loop min to max iterations
        A->>R: Evaluate draft
        R-->>A: Improve or accept
    end
    A-->>U: Final answer
```

After each response, the agent runs one or more reflection passes (between `min_iterations` and `max_iterations`). Each pass asks whether the answer meets quality criteria; if not, the agent revises before returning.

***

## Configuration Options

<Card title="ReflectionConfig SDK Reference" icon="code" href="/docs/sdk/reference/python/classes/ReflectionConfig">
  Full parameter reference for ReflectionConfig
</Card>

**Precedence ladder** — choose the level you need:

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Level 1: Bool (simplest — enable with defaults)
agent = Agent(reflection=True)

# Level 2: ReflectionConfig (full control)
agent = Agent(reflection=ReflectionConfig(
    min_iterations=1,
    max_iterations=3,
    llm="gpt-4o",
    prompt="Evaluate for accuracy, completeness, and clarity.",
))
```

| Option           | Type          | Default | Description                                    |
| ---------------- | ------------- | ------- | ---------------------------------------------- |
| `min_iterations` | `int`         | `1`     | Minimum reflection passes                      |
| `max_iterations` | `int`         | `3`     | Maximum reflection passes                      |
| `llm`            | `str \| None` | `None`  | Model for reflection (defaults to agent model) |
| `prompt`         | `str \| None` | `None`  | Custom evaluation prompt                       |

***

## Choosing Reflection Strength

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    Q{Need higher quality?} -->|No| Off[reflection=False<br/>fastest]
    Q -->|Yes| Q2{Latency budget?}
    Q2 -->|Tight| Light[reflection=True<br/>defaults 1–3]
    Q2 -->|Flexible| Heavy[ReflectionConfig<br/>max_iterations=5]

    classDef q fill:#F59E0B,stroke:#7C90A0,color:#fff
    classDef opt fill:#189AB4,stroke:#7C90A0,color:#fff
    classDef off fill:#6366F1,stroke:#7C90A0,color:#fff

    class Q,Q2 q
    class Light,Heavy opt
    class Off off
```

***

## Best Practices

<AccordionGroup>
  <Accordion title="Disable for tool-heavy agents">
    Reflection adds an extra LLM pass per turn. Set `reflection=False` on agents that call tools frequently to keep latency down.
  </Accordion>

  <Accordion title="Pair with a dedicated reflection model">
    Use `ReflectionConfig(llm="gpt-4o")` when the main model is fast but you want a stronger critic.
  </Accordion>

  <Accordion title="Do not confuse with self_improve">
    `reflection` improves *this* answer within the task. `self_improve` captures reusable skills for *next* time — they compose independently.
  </Accordion>

  <Accordion title="Set max_iterations for cost control">
    Cap `max_iterations` in production to avoid runaway loops on open-ended prompts.
  </Accordion>
</AccordionGroup>

***

## Related

<CardGroup cols={2}>
  <Card title="Self Improve" icon="sparkles" href="/docs/features/self-improve">
    Capture reusable skills after each task
  </Card>

  <Card title="Guardrails" icon="shield" href="/docs/features/guardrails">
    Validate agent outputs with policies
  </Card>

  <Card title="Planning Mode" icon="list-check" href="/docs/features/planning-mode">
    Let agents plan before acting
  </Card>

  <Card title="Execution Systems" icon="play" href="/docs/features/execution-systems">
    Configure agent execution limits
  </Card>
</CardGroup>
