Skip to content

reflexion

reflexion is a self-improvement loop: the agent acts, evaluates its output, reflects on what to do differently, and repeats until satisfied.

  • Tasks requiring iterative self-improvement
  • Agents that need to learn from mistakes within a single run
  • Complex reasoning where the first attempt is rarely optimal
  • Code generation with self-testing
agents/my-reflexion/
├── AGENT.md ← pattern: reflexion, max_iter, config
└── reflect.md ← system prompt for the reflection step
---
name: code-improver
description: Writes and iteratively improves code through reflection.
version: "1.0.0"
pattern: reflexion
max_iter: 4
call:
model:
role: thinker
---
You are an expert programmer. Write code that solves the given task.
After each attempt, you will receive a reflection with improvement suggestions.
Incorporate the feedback and produce a better solution.
When your solution is complete and well-tested, call finish with key="DONE" and the final code.
Call finish with key="DONE" (uppercase) to exit the loop early if satisfied.
---
call:
model:
role: thinker
temperature: 0.1
---
You are a code reviewer. You have just seen an attempted solution.
Evaluate it on:
1. Correctness — does it handle edge cases?
2. Efficiency — is the algorithm optimal?
3. Readability — is it clean and well-commented?
Provide specific, actionable feedback for the next iteration.
If the solution is already excellent, call finish with key="DONE" to stop the loop.
Otherwise, call finish with key="continue" with your critique as the value.
Terminal window
tama add reflexion my-agent
start() → task
[act: AGENT.md body] → attempt
[reflect: reflect.md] → critique or DONE
if DONE → exit loop
if continue → back to act with critique in context
(repeat up to max_iter times)

The reflect step controls the loop:

  • finish(key="DONE", ...) — exit the loop, return the result
  • Any other key — continue to the next iteration

The max_iter field caps the total number of act-reflect cycles (default: 4 for reflexion).

Use "DONE" (uppercase) to signal completion from within the loop. This is a convention — the reflexion runtime specifically checks for this key to exit.