Skip to main content
Enable reflection=True on an agent and it critiques its own answer before returning — improving quality within the same task.
The user asks a question; the agent drafts an answer, reflects on quality, then returns the improved response.

Quick Start

1

Simple Usage

2

With Configuration


How It Works

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

ReflectionConfig SDK Reference

Full parameter reference for ReflectionConfig
Precedence ladder — choose the level you need:
OptionTypeDefaultDescription
min_iterationsint1Minimum reflection passes
max_iterationsint3Maximum reflection passes
llmstr | NoneNoneModel for reflection (defaults to agent model)
promptstr | NoneNoneCustom evaluation prompt

Choosing Reflection Strength


Best Practices

Reflection adds an extra LLM pass per turn. Set reflection=False on agents that call tools frequently to keep latency down.
Use ReflectionConfig(llm="gpt-4o") when the main model is fast but you want a stronger critic.
reflection improves this answer within the task. self_improve captures reusable skills for next time — they compose independently.
Cap max_iterations in production to avoid runaway loops on open-ended prompts.

Self Improve

Capture reusable skills after each task

Guardrails

Validate agent outputs with policies

Planning Mode

Let agents plan before acting

Execution Systems

Configure agent execution limits