Search Strategies
Reflexion
Reflexion
A draft-critique-refine loop bounded by the hop ceiling. The gate jumps backward on low scores to retry the draft with the critique in context.
Shape and when to use
Shape: draft followed by critique followed by a gate that jumps back to draft on low score followed by refine.
When to use: tasks with a verifiable correctness signal (math, code, logic, structured output). Reflexion works when the critique can identify concrete errors for the next draft pass to fix. Less useful for purely subjective tasks where "better" is not measurable.
Cost: 3 LLM calls per loop iteration multiplied by maxLoops. Bounded by the hop ceiling (default 200 hops, so up to ~66 reflexion iterations). In practice, set executionBudget.maxHops to bound iterations explicitly.
Config sketch
See Add Reflexion tutorial for the full ladder. The load-bearing piece is the gate's backward jump:
- id: critique
if:
jsonMatches:
type: object
required: [score]
properties:
score: { type: integer, minimum: 8 }
additionalProperties: true
then: continue
else:
jump: { stepId: draft }When the critique's score is below 8, the engine repositions its step cursor back to draft. The next loop iteration's draft step can ingest the prior critique via loopRef: previous, giving the drafter the feedback to improve.
Termination
Reflexion loops terminate via one of:
- Gate passes. Score crosses the threshold; the gate's
then: continuefires; the ladder advances past the critique step. - Hop ceiling. Every loop iteration, jump, and recursion level counts as hops against the ladder's declared
executionBudget.maxHops. When the ceiling is exceeded, the runtime publishes anerrorevent withceiling_exceeded: trueand returns the best-so-far output. - Spend ceiling. Same as hop ceiling, but triggered by
maxSpendafter an LLM call.
There is no static guarantee that reflexion converges. The runtime ceilings are the safety net. Always set executionBudget.maxHops to a value that bounds iterations to what your budget allows.
Common pitfalls
- Reflexion on factual recall. "What is the capital of France?" does not improve from a critique step. The model either knows it or doesn't. Reflexion works on tasks where the model can identify and fix its own errors.
- No critique feedback into the draft. If the next loop's
draftstep does not ingest the priorcritiqueoutput (vialoopRef: previous), the loop just retries the same draft. Always thread the critique back. - Threshold too high. If the gate's score threshold is unattainable, the loop burns the entire hop budget and exits with the last attempt. Calibrate the threshold empirically on a test set.