Self-reflection loops with ReflectionConfig

Critique and refine outputs automatically before returning

First drafts from any LLM often miss a subtle constraint. Enable reflection=True or ReflectionConfig(min_iterations=1, max_iterations=2) so the agent critiques its own answer and revises it before replying.

Example

from praisonai import Agent, ReflectionConfig

refl = ReflectionConfig(
    min_iterations=1,
    max_iterations=1,
    prompt='Verify exact numbers ($4.2M, +18%, 1.4%) appear in under 2 sentences.',
)
analyst = Agent(
    name='ReflectiveAnalyst',
    instructions='Write a crisp executive summary citing exact figures.',
    reflection=refl,
    output='silent',
)
print(analyst.start('Q3 metrics: revenue $4.2M (+18% YoY), churn 1.4%.'))

Try it Yourself

Example explained

  • ReflectionConfig(min_iterations=1, max_iterations=2, prompt=…) — Bounds critique-and-revise passes with custom review criteria.
  • reflection=True — One-line shorthand using sensible default reflection bounds.

Pair a strong critic prompt with tight max_iterations

Give reflection prompt concrete checks ('verify no placeholder text', 'check JSON syntax'). Cap max_iterations at 2–3 so reflection stays fast and predictable.

Common pitfall: unbounded reflection inflating latency 5x

Every reflection pass adds another LLM call. Use reflection selectively on high-stakes final writing or code generation — not on every intermediate helper step.

Reference: documentation