# `ExAthena.Modes.Reflexion`
[🔗](https://github.com/udin-io/ex_athena/blob/v0.7.1/lib/ex_athena/modes/reflexion.ex#L1)

Reflexion mode: after each ReAct iteration, insert a short self-critique
pass before the next turn.

Per the Reflexion paper (Shinn et al.) — and validated in the research
phase of v0.3 — self-critique is most useful when capped at **3
reflection cycles**. Beyond that, models exhibit degeneration-of-thought
(looping on the same critique or contradicting themselves).

## How it works

Each ReAct iteration calls the provider. On `{:continue, state}` return,
this mode injects a synthetic user message with a reflection prompt,
lets the model critique its own last turn, and adds the critique to
history before the next iteration.

Skips reflection when:
  * Iteration count ≥ `:max_reflections` (default 3, hard cap at 3).
  * The ReAct turn halted (we're terminating anyway).

## State

`state.mode_state[:reflections]` counts performed reflections.

## Trade-off

Reflexion roughly triples per-loop cost (one extra inference per turn
for the critique). Best reserved for tasks where correctness matters
more than speed — research-style fact-checking, structured extraction
at the edge of the model's ability, etc.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
