How AI Agents Learn From Execution Feedback

AI agents improve within a task by running their work, reading the result and retrying. We traced the loop through ReAct, Reflexion, Self-Refine, SWE-bench and Claude Code’s verification advice.

Smiling engineer reviewing agent test results at his desk

In the Reflexion paper, a coding agent reached 91% pass@1 on the HumanEval benchmark. GPT-4 on its own scored 80%. Nobody retrained the model to close that gap. The agent ran its code, read what failed and tried again with notes on its own mistakes.

That is how AI agents learn from execution feedback. They act, check the real result and carry that result into the next attempt. So the learning lives in the prompt, the memory and the files around the model. The weights do not change at all.

We read the ReAct, Reflexion and Self-Refine papers, the SWE-bench test harness and Anthropic’s coding guidance side by side. Our aim was to see where this loop works and where it quietly breaks.

What Execution Feedback Means for an AI Agent

Execution feedback is any signal that comes from actually running something. A test passes or fails. A compiler throws an error. An API returns a 404. A browser screenshot shows a button in the wrong place.

Anthropic’s guide on building effective agents makes the same point. Agents need “ground truth” from the environment at each step, such as tool results or code execution, to judge their progress. So the model stops guessing about its own work and reads evidence instead.

For a coding agent, that evidence separates code that looks right from code that runs. For a browser agent, it separates a form that seems filled from a form the site accepted.

The Act, Observe, Retry Loop in Six Steps

Every feedback loop we studied follows the same cycle, whatever the framework or vendor.

  1. Plan: the model reads the task and picks the next action.
  2. Act: it calls a tool, edits a file or runs a command.
  3. Observe: the surrounding code captures the output, the error text or the exit code.
  4. Judge: a test, a rule or a second model decides pass or fail.
  5. Reflect: on a failure, the agent writes down what went wrong and why.
  6. Retry or stop: it tries again with that note in context, or it stops at a set limit.

The Claude Agent SDK team sums up the same cycle in four steps: gather context, take action, verify work, repeat. Their post on building agents with the SDK also ranks feedback types. The best kind, they write, is a set of well-defined rules for the output, plus an explanation of which rules failed and why.

Feedback Signals an AI Agent Can Read

Not every signal deserves the same trust. We sorted the common ones by how exact they are.

SignalExampleHow far to trust itTypical use
Unit and integration testspytest exit code and failing test namesHigh, if the tests themselves are rightCoding agents, SWE-bench
Compiler or type checkerTypeScript build errorsHigh for syntax and typesAny code change
LinterESLint rule violationsHigh for style rulesRules-based feedback in the Claude Agent SDK guide
Tool and API responsesHTTP status, error message, empty search resultMedium, since errors can be vagueReAct-style tool use
Screenshots and rendersA browser screenshot of the pageMedium, since a model must read itUI and browser agents
Model as judgeA second model grades the outputLower for exact factsWriting, tone, summaries
Human reviewApprove or reject in a review screenHigh, but slowRisky or costly actions

Order matters too. So run cheap, exact checks first. A type error takes seconds to find, while a model judge costs another full model call.

Read also: How AI Agents Work: Architecture, Components and Execution Flow

Research Behind Feedback-Driven AI Agents

Three papers shaped how agents use feedback today. Each one adds a different piece to the loop.

ReAct Mixed Reasoning With Real Actions

The ReAct paper by Shunyu Yao and co-authors had the model write a thought, take an action and then read the observation. For question answering, the actions hit a basic Wikipedia API. The authors report that this cut the hallucination and error propagation seen in chain-of-thought reasoning.

On the ALFWorld and WebShop tasks, ReAct beat imitation and reinforcement learning methods by 34 and 10 points of absolute success rate. Even so, it needed only one or two examples in the prompt. The lesson for builders is timing. Feedback helps most when it lands in the very next step, while the plan can still change.

Reflexion Turned Failures Into Written Lessons

Reflexion, by Noah Shinn and co-authors, added memory to the loop. After a failed attempt, the agent writes a short reflection on what went wrong. That text goes into an episodic memory buffer and guides the next trial.

The authors describe it as reinforcing agents through language feedback instead of weight updates. The feedback can be a number or free-form text. It can come from the environment or from the agent’s own checks. That design produced the 91% HumanEval result.

Self-Refine Graded Its Own Drafts

Self-Refine, led by Aman Madaan, uses one model in three roles. It writes a draft, critiques it and then rewrites it. There is no training data and no reinforcement learning. Across 7 tasks with GPT-3.5, ChatGPT and GPT-4, the paper reports gains of about 20% absolute on average.

Self-critique helps even when there is nothing to run. However, the critic is the same model that wrote the draft, so it can share the draft’s blind spots. A test suite has no such bias. For how these papers shape planning, read dynamic planning in LLM agents.

Why Tests Give Coding Agents the Best Feedback

Code has a rare property. You can check it by running it. Anthropic’s agent guide says code solutions can be verified through automated tests, so agents can iterate using test results as feedback.

SWE-bench is built on that idea. The original SWE-bench paper collected 2,294 tasks from real GitHub issues across 12 Python repositories. At launch, the best model, Claude 2, resolved just 1.96% of them.

swebench.com
SWE-bench Evaluation Harness Docs website screenshot
SWE-bench Evaluation Harness Docs

Scoring is pure execution. The SWE-bench harness applies the agent’s patch and then runs two groups of tests. FAIL_TO_PASS tests must flip from failing to passing, which proves the fix. PASS_TO_PASS tests must keep passing, which proves nothing else broke. A task counts as resolved only when both groups pass in full.

SWE-bench Verified narrows this to 500 tasks that human annotators reviewed. They checked each one for a well-written problem statement, correct tests and enough information to solve it.

Copy the two-group idea into your own agent. One group proves the new behavior, and the other guards everything that already worked. Our AI agent benchmarking guide puts SWE-bench next to other public tests. For building your own task set, read how to build AI agent evaluation datasets.

A Test-Driven Feedback Loop You Can Copy

Claude Code’s best practices page says a runnable check is the difference between “a session you watch and one you walk away from.” Without such a check, Claude stops once the work looks done. Then you become the check, and every mistake waits for you to notice it.

We turned that advice and the SWE-bench scoring into a routine for any coding agent.

  1. Write a failing test first, or ask the agent to write one that reproduces the bug.
  2. Run it and confirm it fails for the right reason before any fix.
  3. Let the agent change the code, run the suite and read the output.
  4. Pass the exact error text back, never a summary of it.
  5. Set a retry cap, so a stuck run ends on its own.
  6. Ask for evidence at the end, meaning the command it ran and the output it got.
  7. Have a fresh reviewer read the diff, such as a subagent or a pull request bot.

Claude Code also offers stricter gates for this loop. A Stop hook can run your check as a script and block the turn from ending until it passes. A /goal condition has a separate evaluator re-check the goal after every turn.

Several agents on our site work this way. OpenHands can run commands and open pull requests while it codes. Devin works in its own cloud machine and tests code there before it opens a pull request. For your own agent, E2B provides cloud sandboxes to run the code in. After that, a review agent such as CodeRabbit adds one more check on each pull request. Browse more in our coding agents list.

Where Execution Feedback Goes Wrong

Feedback loops fail in a handful of repeat patterns. Each one has a known fix.

  • The agent edits the test: a test the agent can rewrite is a weak judge. In Anthropic’s long-running agent harness, coding agents may only change a passes field in the feature list. The prompt states, “It is unacceptable to remove or edit tests.”
  • A shallow check passes: the same Anthropic team saw Claude mark features done after unit tests or curl calls, with no end-to-end check. Telling it to test through browser automation, as a human user would, greatly improved results.
  • Another model is the only judge: a model can grade fuzzy rules. Still, the Agent SDK team rates it lower than rules-based checks, so save it for tasks with nothing to run.
  • The loop never ends: Anthropic’s guide recommends stopping conditions, such as a cap on iterations. In LangGraph, a runaway graph stops with a GraphRecursionError.
  • Old failures crowd the context: Claude Code’s docs suggest a fresh session after two failed corrections on the same issue, with a sharper prompt.
  • The error arrives half-read: cut-off logs hide the line that matters. So pass the failing test name and the full assertion message.

Long runs also eat context and money. For the first problem, read up on context engineering. For the second, read how to control AI agent costs before you raise any retry cap.

Keeping Lessons After the Run Ends

Within one run, feedback lives in the context window. Across runs, it needs a home on disk or in a database.

Reflexion’s memory buffer is one version. Anthropic’s long-running harness uses plainer tools. It keeps a progress log, git commits and a JSON list of features marked passing or failing. Each new session reads them before it writes a line of code.

Store lessons as short rules. “Run migrations before the tests” helps the next run, while a 4,000-line log of a failed attempt mostly fills space. Where to save that state is covered in AI agent state across sessions. The code that reads and writes it is part of the AI agent harness.

Execution Feedback Questions From Agent Builders

Does execution feedback change the model’s weights?

No. In every method covered here, the model stays the same. Reflexion’s authors describe their approach as reinforcing agents through language instead of weight updates.

Can non-coding agents learn from execution feedback?

Yes, as long as there is something to check. A research agent can test that each cited link loads. A data agent can compare row counts before and after a change. Where no check exists, a rubric with a model judge or a human reviewer fills the gap. For risky steps, see where to place a person in human-in-the-loop orchestration.

How many retries should an agent get?

None of the papers we read sets one number. Set a cap per task, log every attempt and raise it only when the logs show late retries succeed. LangGraph’s default recursion limit is 1,000 super-steps, so pick a lower limit for short tasks.

Is a model judge good enough as feedback?

For tone and style, it does a decent job. For facts and code, prefer a check that runs. Anthropic’s SDK team ranks a model judge under rules and linting for exactly that reason.

Related AI Agents

Read also: Hiring an AI Copywriter? Pick It by the Copy You Need Written

Explore Agent Categories

Related Articles

Joydeep Bhattacharya Avatar

Written by