Self-Improving AI Agents: How They Actually Get Better

How AI agents improve today: offline eval-and-fix loops, in-context methods like Reflexion and Voyager, and RL fine-tuning with GRPO. Plus the risks.

By AI Agents DirectoryLast checked
Green characters streaming down a dark screen

“Self-improving agent” sounds like software that wakes up smarter every morning. That is not how agents in production work today. The model inside a typical agent has fixed weights; it reacts to tool output within a task, but it does not retrain itself from yesterday’s conversations. Agents get better in three real ways: teams improve them offline from logged traces, the agent uses feedback inside its own context (Reflexion, Voyager, Self-Refine), or someone runs reinforcement learning on the model against a reward. This guide covers each, with the risks that come with them.

What an agent is, and where improvement can happen

Anthropic describes agents as being “typically just LLMs using tools based on environmental feedback in a loop” (Building effective agents). That gives you three places to change behaviour:

LayerWhat changesWho changes itExample
HarnessPrompts, tools, tool docs, guardrailsYour team, after reviewing tracesFix a confusing tool description
ContextNotes, reflections, stored skillsThe agent, during or between attemptsReflexion memory, Voyager skill library
WeightsThe model itselfA training job you runGRPO fine-tuning on task rewards

Only the last one is “learning” in the machine learning sense, and it happens in a training run, not live in front of users.

1. Offline improvement loops

This is where most real-world improvement comes from, and it is mostly engineering discipline.

  1. Log full traces. Anthropic’s eval guide defines a transcript (also called a trace or trajectory) as the full record of a run: outputs, tool calls, reasoning and intermediate results. A tracing tool such as Langfuse can capture these.
  2. Turn failures into test cases. Anthropic suggests mining your bug tracker and support queue, then converting failures users reported into eval tasks, ranked by user impact.
  3. Grade outcomes, not just words. Their example: a flight agent can say the booking succeeded, but the real outcome is whether a reservation row exists in the database. Prefer deterministic checks where you can, use LLM graders where you must, and calibrate those graders against human experts. Our guide to LLM evaluation metrics covers the scoring side.
  4. Fix the cheapest layer first. Many failures are a vague prompt or a badly documented tool. Change one thing, rerun the suite, and read the transcripts.
  5. Fine-tune when the harness is not enough. If the same class of mistake survives prompt and tool fixes, collect good trajectories and train on them; see fine-tuning domain-specific AI agents.

Anthropic recommends keeping two suites: capability evals you are trying to climb, and regression evals that should stay close to fully passing so a change in one area does not quietly break another. Without them, the guide warns, teams end up debugging reactively and cannot tell a real regression from noise.

2. In-context self-improvement

These methods let an agent do better on a second or later attempt without touching the model’s weights.

Reflexion: learning from verbal feedback

Reflexion (Shinn et al., 2023) reinforces an agent through language rather than gradient updates. After a trial, the agent writes a reflection on the feedback signal (a failed unit test, a score, or a self-critique), stores that text in an episodic memory buffer, and reads it on the next try. The paper reports gains on decision-making, coding and reasoning tasks, including a HumanEval result above the GPT-4 baseline of the time.

The practical catch: Reflexion needs repeated attempts at the same or similar task, plus a feedback signal worth reflecting on. Tests for code are ideal. Vague user satisfaction is not.

Voyager: a growing library of skills

Voyager (Wang et al., 2023) plays Minecraft using GPT-4 through black-box queries, with no parameter fine-tuning. It combines an automatic curriculum that pushes exploration, a skill library of executable code it keeps adding to and retrieving from, and an iterative prompting loop that uses environment feedback, execution errors and self-verification. Because skills are stored as code, they are interpretable and can be reused in a new world. The authors report it collected 3.3x more unique items than earlier methods.

The idea transfers well beyond games: when an agent solves a recurring task, save the working procedure (a script, a query, a checklist) and let it retrieve that next time.

Self-Refine: critique and rewrite

Self-Refine (Madaan et al., 2023) is the simplest of the three. One model drafts an answer, critiques its own draft, and revises, repeating as needed. It uses no extra training data and no RL. Across seven tasks with GPT-3.5, ChatGPT and GPT-4, both humans and automatic metrics preferred the refined outputs over single-pass ones. Anthropic’s “evaluator-optimizer” workflow is the same pattern with the critic as a separate call, and it suggests using it when you have clear evaluation criteria.

None of these methods make the agent permanently better at its job unless you persist what it learned (reflections, skills) and test that the stored material actually helps.

3. RL fine-tuning on environment rewards

To change the weights, you train the model on rewards from tasks where success can be checked. A common method today is GRPO (Group Relative Policy Optimization), introduced in the DeepSeekMath paper as a PPO variant that also cuts PPO’s memory use. The GRPO trainer in Hugging Face TRL works like this:

  • For each prompt, the model generates a group of completions.
  • Each completion is scored by a reward model or a reward function you write.
  • Each reward is compared with the group’s mean (normalised by the standard deviation by default), so the model learns which of its own attempts were better than its siblings.

TRL calls GRPO an online method: it learns from data the model itself generates during training. For RL background and the KL penalty idea, see our RLHF explainer. One detail worth knowing: TRL sets the KL coefficient beta to 0.0 by default, so the KL term is switched off unless you set it.

TRL’s docs include agent training, where the model calls tools during generation and is rewarded on the outcome. An environment class supplies the task via reset(), exposes its public methods as tools, and can score the episode itself with get_reward(). This is the docs’ minimal example (it needs transformers>=5.2.0):

import random
from trl import GRPOConfig, GRPOTrainer

class IncrementEnv:
    def reset(self, **kwargs) -> str | None:
        self.counter = 0
        self.target = random.randint(1, 6)
        return f"Increment the counter by {self.target}."

    def get_reward(self) -> float:
        return float(self.counter == self.target)

    def increment(self, step: int) -> int:
        """
        Increment the internal counter.

        Args:
            step: Value to add to the counter.

        Returns:
            The updated counter value.
        """
        self.counter += step
        return self.counter

trainer = GRPOTrainer(
    model="Qwen/Qwen3-0.6B",
    args=GRPOConfig(max_steps=1000, chat_template_kwargs={"enable_thinking": False}),
    environment_factory=IncrementEnv,
)
trainer.train()

Swap the toy counter for your real task (a sandboxed codebase with tests, a mock CRM with a checkable end state) and the reward for an outcome check. Use max_tool_calling_iterations in GRPOConfig to cap tool turns, since by default there is no limit. Budget real compute: TRL’s own quick start, a 0.5B model on a maths dataset, takes about a day on 8 GPUs.

Risks to plan for

Reward hacking. Concrete Problems in AI Safety (Amodei et al., 2016) lists avoiding reward hacking among five practical accident-risk problems. An agent optimised against a grader will find the grader’s gaps. Anthropic’s eval guide tells teams to make graders resistant to bypasses so that passing requires actually solving the task. It also notes the reverse case: Claude Opus 4.5 “failed” a τ2-bench flight-booking task by finding a policy loophole that was arguably a better answer. Either way, the fix is the same: read transcripts, not just scores.

Regressions without evals. Every prompt edit, stored reflection or new checkpoint can break something that used to work. Run your regression suite on each change, and treat a training run like any other release: compare the new model with the old one on the same tasks before it goes live.

Bad memory. In-context methods can store wrong lessons. Reflections and skills need the same review and testing as code.

Unsafe exploration. RL agents act to see what happens. Anthropic recommends extensive testing in sandboxed environments with guardrails, and training should happen there too, never against production systems.

If you are choosing tools for tracing and evals, the evaluation and monitoring category lists options.

#AI agents#Reinforcement learning#Agent evaluation#GRPO#Reflexion
AI

Written by AI Agents Directory

Editorial team

Facts in this guide are checked against official documentation and repositories, which are linked in the article.