Agent-Reflex: Verified Training for Recovery
Language agents can make tool errors, flawed plans, or misunderstand user intent; Agent-Reflex trains recovery by adding verifier-accepted continuations for local repair, task restart, and user correction.
Read the paper ↗What it is
- Local repair Continue from just before the first mistaken action, using temporary guidance to generate a fix but leaving that guidance out of the stored example.
- Plan restart When the original approach is flawed, start over from the task’s initial state instead of patching the failed plan.
- User-guided replanning Turn a recovery skill into a natural user correction, then train the agent to reconsider its next steps in that visible conversation.
Why it matters
Agents need different recoveries for tool mistakes, bad plans, and misunderstandings. Verifier-accepted continuations teach those distinctions while keeping hidden state and private skill prompts out of the policy’s stored inputs.
Before we get into the mechanics, here is the short version: Agent-Reflex creates training examples where an agent recovers from a mistake, starts over when its plan is wrong, or changes course after a user correction. The examples are kept only when the environment accepts the completed task, and the training context is shaped to look like something the agent could actually see.
- Recovery is not one behavior: A tool call can go wrong locally, or the whole plan can be wrong. Those are different problems. If I break one step in a working plan, I want a repair; if the plan's premise is bad, patching the next step just digs deeper.
- Training needs a useful target: Successful examples show what completion looks like, but not necessarily how to get unstuck. The recipe generates continuations from failed attempts and filters for task completion, so the target is a recovery that actually works in the environment.
- The user can change the problem: Sometimes the issue is not a broken tool but a mismatch with intent. Then recovery should react to what the user says, without treating every correction as automatically correct.
So where should the agent pick up after an error? The canonical example is a wrong tool call in the middle of an otherwise sensible workflow. The environment can be restored to just before that call, so the continuation gets a chance to repair locally rather than inheriting the bad state. The matched recovery skill is used while generating that continuation, but it is removed from the stored example; the agent is meant to learn the repair pattern, not depend on a secret instruction at run time. Generalize this to other first-error points: the key is resuming from the state where a local fix is possible. What if the problem is the plan, not the tool call?
For that, imagine booking the wrong kind of trip because the initial interpretation was off. Repeating the next booking step more carefully will not help; the agent needs to reconsider the original task. Skill Recovery Sampling resets to the initial state and starts again from the task, with temporary guidance used to produce the restart. Again, that privileged guidance is left out of the stored input. The distinction is like editing a mistaken line in a notebook versus opening a fresh page; the analogy stops short because the environment state, not just the written plan, must also be restored. So what if the missing correction comes from a person?
User-Centric Reflection Sampling turns the recovery skill into a natural-language user message. Think of a user saying, “That’s not what I meant—please do this instead.” The agent resumes from the error-time state, sees that message, and replans. Unlike the private skill prompt, the synthesized correction stays in the training context because a user message is something the deployed agent can see. But the user may be ambiguous or even wrong, so the desired behavior is to reason about the correction, not obey it reflexively. How do we know these generated recoveries are worth learning from?
The environment verifier checks whether a resulting episode completes the task; only accepted continuations join the reflective data. The stored examples also omit simulator state snapshots: those are used to restore the environment, not shown to the agent as text. In the reported setup, the shared continuation actor is Qwen3-8B, and the UR user simulator is GPT-4.1; the final corpus combines verified starting-policy successes with SR, KR, and UR examples. I like the clean separation between “what the generator needed” and “what the learner gets.” The caveat is that a verifier checks the environment’s completion criterion, not every nuance of whether the recovery was sensible. So ReSFT gives the agent structured practice recovering; it does not make every unfamiliar failure easy.
Read the deep dive
Why People Wanted It
An agent can fail in more than one way. It may make a local mistake while using a tool, commit to a bad plan that needs a fresh start, or drift from what the user meant and need to respond to a correction. Ordinary successful demonstrations mostly teach what a good trajectory looks like; they do not necessarily teach what to do once the agent is already off course. So the real question was never just how to collect more examples. It was how to turn recovery into behavior the policy can learn, while keeping training inputs close to what the agent could actually see at deployment.
The Core Move
Reflective Supervised Fine-Tuning (ReSFT) creates three kinds of recovery continuations, accepts only episodes the environment verifier marks successful, and trains on the visible context without exposing privileged recovery skills. The distinction is where recovery begins: the error state, the original task state, or a user-correction turn.
Why the Restart Point Changes the Skill
Here is the part that gets technical: SR and KR differ not just in wording but in the state from which the continuation is generated. For an erroneous trajectory, let be its first wrong turn, the environment snapshot before that turn, and the visible history. Let be the matched recovery skill. A continuation is retained only if the verifier says it completes the task from the restored state.
In Self-Reflection Sampling (SR), restore and continue from the history with the skill appended as temporary guidance. In compact form, , with the requirement that . This says: generate a repair from the point just before the first error, then keep it only when the environment accepts the completed episode. The skill helps elicit the continuation but is removed from the stored input, so the learned example asks the policy to recover without a hidden skill prompt.
KR targets a different failure: the initial plan itself may be wrong, so repairing the next tool call is not enough. Skill Recovery Sampling restores the initial state and restarts with the original task and temporary skill guidance: , again retaining only verifier-accepted completions. In words, the agent gets another attempt from the beginning, rather than being trained to patch a plan whose premise has failed. Its skill text is also removed before storage. The question this leaves open is how to teach recovery when the missing information comes from the user, not the environment?
Why User Corrections Stay Visible
Now the version for readers who want more of the machinery: UR turns the matched skill into a natural-language user message, rather than placing the skill itself in the agent's context. A simulator maps the skill and error-time context to a correction, . This means the policy receives an ordinary conversational intervention; the privileged skill is not passed through as a prompt.
The environment is restored to , the correction is inserted after the erroneous turn, and the continuation is sampled from that corrected interaction. Unlike SR and KR, the synthesized message remains in the stored input because a user turn is deployment-visible. The correction is not automatically a command to obey: the simulator can produce direct corrections, partial hints, ambiguity, or deliberately incorrect advice. That setup makes the target behavior replanning in context, not blind compliance. How can these distinct recovery targets become plain training examples without leaking the machinery that generated them?
Why the Stored Dataset Is Deployment-Shaped
The training merge combines successful trajectories from the starting policy with the verifier-accepted SR, KR, and UR continuations. The crucial constraint is what the policy sees: simulator snapshots restore environment state but are never serialized as context; SR and KR skill text is removed; UR retains the rewritten user message but not the skill prompt. Thus the stored examples preserve the useful visible interaction while withholding privileged state and skill instructions.
The continuation actor is Qwen3-8B, matching the trained backbone, and the UR user simulator is GPT-4.1. A sample enters the corpus only when the environment verifier accepts the episode. The resulting corpus contains 54K trajectories, combining verified starting-policy successes with reflective corrections across the three sampling strategies. These details define the data-generation setup; the learning target remains the visible recovery behavior. What does this carefully shaped supervision buy, and what does it leave unsolved?
Minimal Causal Code
This sketch makes the three restore points and the verifier gate visible. The rollout and environment interfaces are schematic; the key is that temporary skill guidance is used to generate candidates but is not automatically copied into stored SR/KR context.
def make_recovery_example(env, policy, verifier, task, history, skill, kind, user_sim=None):
if kind == "SR":
snapshot = env.snapshot_before_first_error()
visible_context = history
env.restore(snapshot)
generation_context = visible_context + [skill]
continuation = policy.generate(generation_context, env)
stored_context = visible_context
elif kind == "KR":
env.reset()
generation_context = [task, skill]
continuation = policy.generate(generation_context, env)
stored_context = [task]
elif kind == "UR":
snapshot = env.snapshot_before_first_error()
env.restore(snapshot)
correction = user_sim.rewrite(skill, history, snapshot)
visible_context = history + [correction]
continuation = policy.generate(visible_context, env)
stored_context = visible_context
else:
raise ValueError("unknown recovery type")
episode = env.finish_episode(continuation)
if verifier.accepts(episode):
return {"context": stored_context, "continuation": continuation}
return None
What You Gain, and What You Lose
You gain supervised examples that distinguish three recovery situations instead of treating every failure as the same: repair from just before an error, restart the original task when the plan is flawed, and replan after a visible user correction. Verifier acceptance filters out continuations that do not complete the task, while removing privileged state and skill text from stored contexts keeps the training input closer to deployment.
You also inherit the limits of generated supervision. Recovery examples depend on the continuation actor, the quality of the matched skill, the simulator's user messages, and the environment verifier's judgment. A verifier can establish task completion according to the environment; it does not by itself guarantee that a recovery explanation is robust or that an ambiguous user correction was interpreted well. ReSFT teaches from accepted examples; it does not eliminate the need to test recovery under new errors and interactions. The next stage, on-policy optimization, is a separate module rather than part of this data-construction story.
Teach recovery from the state that matches the failure: repair locally, restart globally, or replan from a visible user correction.