AgentTeam(reflection=…) is not wired yet (PraisonAI #4004) — set reflection=… on each Agent(...) in the team instead.Quick Start
1
Level 1 — Bool (simplest)
Turn on self-review with a single flag.
2
Level 2 — Config class (tune iterations and LLM)
Use
ReflectionConfig to control how many review passes run and which LLM critiques.3
Level 3 — Config with a custom review prompt
Pass a domain-specific
prompt to steer what the self-review checks for.How It Works
If a reflection response cannot be parsed (for example, an OpenAI structured-output refusal, a content-filter block, or a truncation), the agent retries that pass. Retries are bounded by
max_iterations — after that many failed passes, the agent returns the current draft un-reflected instead of continuing to retry.
Troubleshooting
Persistent parse failures terminate cleanly atmax_iterations instead of looping forever.
When the reflection LLM keeps returning an unparseable response (a structured-output refusal, a content-filter block, or a
finish_reason="length" truncation), the agent stops after max_iterations failed passes and returns the current draft un-reflected.When the reflection agent’s underlying model triggers a content filter / refusal / length cutoff, the outer run’s agent.last_stop_reason is set to content_filtered / refused / length_truncated — see Run Outcome.With output="verbose" (or output=OutputConfig(verbose=True)), look for this log line on the terminating pass:Maximum reflection count reached after repeated parse errors, returning current responseIf you see it often:- Lower
max_iterationsto fail fast. - Switch the reflection LLM with
ReflectionConfig(llm=...)to one less prone to refusals. - Narrow the
promptso the reflection response fits the required JSON shape.
chat() returns None and the chat history is rolled back to the pre-turn state.What you see if reflection cannot parse
1
Call the agent
You call
agent.chat("...") on an agent with reflection=True.2
Draft and critique
The agent generates a draft, then asks its reflection LLM to critique it.
3
Reflection cannot parse
The reflection LLM returns a structured-output refusal (or the response is filtered / truncated), so parsing raises.
4
Retry, bounded
The agent logs
Error in parsing self-reflection json ... Retrying and tries again — up to max_iterations times.5
Terminate and return
After
max_iterations failed passes, the agent logs Maximum reflection count reached after repeated parse errors, returning current response and returns the current draft. If a guardrail rejects that draft, chat() returns None and the chat history is rolled back.Configuration Options
Full list of options, types, and defaults —
ReflectionConfigCommon Patterns
Pattern 1 — Quality-focused writing
Pattern 2 — Factual accuracy check
Best Practices
When to use reflection
When to use reflection
Enable reflection for writing tasks, technical explanations, and any output where quality matters more than speed. Skip it for simple lookups, calculations, or real-time applications.
Set max_iterations to control cost
Set max_iterations to control cost
Each reflection pass costs an additional LLM call. Set
max_iterations=1 for light review, 2 for thorough review, and only go to 3 for high-stakes content. The default is 3. max_iterations also bounds parse-error retries — not just “not-yet-good-enough” passes — so a reflection LLM that keeps refusing can’t loop forever.Use a custom prompt for domain-specific review
Use a custom prompt for domain-specific review
Default reflection uses general quality criteria. Pass a
prompt tailored to your domain — e.g., “Check for HIPAA compliance language” for medical agents or “Verify all code is PEP 8 compliant” for coding agents.Related
Planning — plan before acting on complex requests
Self-Reflection Deep Dive — advanced reflection patterns

