Learning agent: getting better from outcomes without retraining
A learning agent records how each task went and turns that record into better examples, routing rules, or prompts. Use it when the same kinds of task repeat and mistakes are costly.
Learning agent in 60 seconds
- What: an agent that records the outcome of every task and uses those records to change how it acts next time.
- How it learns: it changes the things around the model (examples, routing rules, prompts, stored lessons), not the model weights.
- Best for: repeated task types such as support triage, data clean-up, or report drafting, where success can be measured.
- Weak spots: bad feedback teaches bad habits, and a change that helps one task type can hurt another.
- Origin: the learning agent is one of the classic agent kinds in Russell and Norvig's textbook, with a critic and a learning element beside the performer.
Where this type fits
In the Types of AI agents hub, the learning agent sits in the first family: how an agent decides. Reactive, planning, ReAct, plan-and-execute, and reflexive agents all decide within a single task. The learning agent adds a decision about the next task. It can be combined with any of the others, because it is less a way of acting and more a loop wrapped around a way of acting.
The problem it solves
Without learning, an agent makes the same mistake on Monday that it made last Friday. Suppose an agent files expense claims. It keeps misreading one supplier's invoice format and sends the claim to the wrong approver. A person fixes each one by hand. The prompt never changes, so the error returns every week, and the people who fix it stop trusting the agent.
The usual response is for an engineer to read logs and edit the prompt. That works, but it is slow and depends on someone noticing. Many teams find that the lessons sit in tickets and chat threads and never reach the agent. The gap between 'we know what went wrong' and 'the agent knows it' can last months.
A learning agent closes that gap in a controlled way. It keeps a structured record of what it did and how things ended. It looks across many records for patterns. It proposes a small change, such as a new worked example for that supplier. After review, the change goes live and the next task benefits.
How it works
- Act: the agent does the task using its current prompt, examples, and rules.
- Observe the outcome: a score is attached to the run. Good scores come from tests, a user accepting or editing the result, a human rating, or a business check such as 'claim approved first time'.
- Record: the run is stored with the input, the steps taken, the outcome, and the cost. Without a stored record there is nothing to learn from.
- Review: a separate step (a model, a person, or both) reads batches of records and proposes a change. This is the learning element. It should never edit the live setup directly.
- Update: an approved change is saved as a new version of an example set, routing table, or prompt. The next task picks up the new version.
- Check: the change is compared with the old version on past records. If results get worse, it is rolled back.
The top row is the ordinary work of an agent. The second row is what makes it a learning agent. The record is the hinge between them: it captures success, the steps taken, and the cost, so a reviewer can tell a cheap success from an expensive one.
The arrow back to 'act' is where the value shows up. It is labelled 'the next task uses it' because a lesson that is stored but never read changes nothing. The review step sits in the middle on purpose. It is the point where a person can say no, and it stops one odd task from rewriting the agent's behaviour.
A worked example
Acme Corp runs an agent that routes incoming invoices to the right approver. It starts with a prompt, a table of routing rules, and four example invoices.
Week 1. The agent handles 200 invoices. Eleven are sent to the wrong approver. Each of these is corrected by a finance clerk, and the correction is stored as the outcome: approver_expected: finance-eu, approver_chosen: finance-us.
Review. At the end of the week, a review model reads the eleven failures. Nine involve the supplier 'Northwind Ltd', whose invoices show a UK address but are billed by the EU office. The reviewer proposes one change: add a worked example for Northwind to the example set, and add a routing rule that supplier names containing 'Northwind' go to finance-eu.
Approval. A finance lead checks the proposal, approves the example, and rejects the broad rule because it could catch a different supplier with a similar name. The example set moves from version 4 to version 5.
Check. The new version is replayed on the previous 200 invoices. Wrong routings fall from eleven to three, and no new errors appear.
Week 2. The agent uses version 5. The next 200 invoices produce four wrong routings, none from Northwind. The record shows the change worked and shows what is left to learn.
{
"run_id": "run-20261109-0142",
"task": "route_invoice",
"prompt_version": 3,
"example_set_version": 4,
"steps": 3,
"cost_units": 12,
"outcome": { "success": false, "reason": "wrong_approver", "expected": "finance-eu", "chosen": "finance-us" }
}
{
"proposal_id": "p-0091",
"change": "add_example",
"target": "example_set",
"evidence_runs": 9,
"status": "pending_review"
}Building it
The code below shows the loop. Every function that calls a model or a store is a placeholder. The important parts are the limits and the review gate.
# Placeholders: llm, store, and reviewer are stand-ins, not real libraries.
MAX_RECORDS_PER_REVIEW = 200 # keep the reviewer's input bounded
MIN_EVIDENCE = 5 # do not learn from one odd case
MAX_CHANGES_PER_WEEK = 3 # slow, reviewable change beats fast drift
def run_task(task, setup):
"""Act using the current versioned setup (prompt, examples, rules)."""
result = llm.generate(build_prompt(task, setup), max_steps=8)
return result
def record_outcome(task, setup, result, outcome):
# Store versions with the record so we know which setup produced it.
store.save_run({
"task": task.id,
"setup_version": setup.version,
"steps": result.steps,
"cost": result.cost,
"success": outcome.success,
"reason": outcome.reason,
})
def propose_changes(setup):
failures = store.recent_failures(limit=MAX_RECORDS_PER_REVIEW)
groups = group_by_reason(failures)
proposals = []
for reason, runs in groups.items():
if len(runs) < MIN_EVIDENCE:
continue # too little evidence
proposals.append(llm.generate(make_review_prompt(reason, runs)))
return proposals[:MAX_CHANGES_PER_WEEK]
def replay_score(setup, runs):
"""Re-run past inputs with a candidate setup; return the success rate."""
ok = sum(1 for r in runs if run_task(r.task, setup).matches(r.expected))
return ok / max(len(runs), 1)
def weekly_update(current):
history = store.sample_runs(limit=MAX_RECORDS_PER_REVIEW)
for p in propose_changes(current):
if not reviewer.approve(p): # a person decides, not the agent
continue
candidate = current.with_change(p) # new version, old one kept
if replay_score(candidate, history) >= replay_score(current, history):
current = candidate
store.publish(current)
return current
Design decisions
- What to change: change examples and routing rules first, prompts second. Do not fine-tune weights unless simpler changes stop helping. Small text changes are easy to read, review, and undo.
- Where records live: keep them in a store you can query by task type, version, and outcome. Append-only is a good default, since you may need to explain a change months later.
- Who approves: start with a person approving every change. Allow automatic approval later only for low-risk change types, such as adding an example, and only after replay checks pass.
- Versioning: every setup has a version number, and every run record stores it. This lets you compare versions and roll back in one step.
- Feedback source: prefer objective signals such as tests or approvals over opinions. If you must use ratings, collect several per sample and note who gave them.
- Cost and latency: run the review offline on a schedule, not during the task. The live path should only read the current version.
- Failure handling: if the review step fails or is unsure, keep the current version. Doing nothing is always a safe default.
Measuring it
- Success rate by version: successful runs divided by all runs, split by setup version. Compare versions on the same task mix, or the numbers mislead.
- Repeat-error rate: the share of failures whose reason was already seen and 'fixed'. If this stays high, the lessons are not reaching the agent.
- Regression rate: on a fixed held-out set, count tasks that passed under the old version and fail under the new one. Any rise is a warning.
- Cost per success: total cost units divided by successful runs. Learning that raises success but doubles cost may not pay off.
- Proposal acceptance rate: approved proposals divided by proposals made. A very low rate means the reviewer is making poor suggestions. A rate near 100 percent may mean approval is a rubber stamp.
def compare_versions(old, new, heldout):
# heldout is a fixed list of tasks with known expected results
old_ok = {t.id for t in heldout if run_task(t, old).matches(t.expected)}
new_ok = {t.id for t in heldout if run_task(t, new).matches(t.expected)}
regressions = old_ok - new_ok # passed before, fail now
gains = new_ok - old_ok
return {
"old_rate": len(old_ok) / len(heldout),
"new_rate": len(new_ok) / len(heldout),
"regressions": sorted(regressions),
"gains": sorted(gains),
}
When to use it, and when not to
| Situation | Use this type? | Why |
|---|---|---|
| The same task type repeats thousands of times | Yes | Patterns in failures appear quickly, and one fix helps many future tasks. |
| Success can be measured by tests, approvals, or clear ratings | Yes | The record needs a trustworthy outcome to learn from. |
| Tasks are one-off and each is different | No | There is nothing to generalise, and a single run teaches little. |
| Mistakes are costly and rules change slowly | Yes, with review | A person-approved change process turns repeat errors into permanent fixes. |
| No one will review changes | No | Unreviewed learning drifts, and errors can compound without notice. |
| Feedback is rare, noisy, or biased | Not yet | Fix the feedback source first. Learning from bad signals makes the agent worse. |
| A simple prompt edit by an engineer is enough | No | A manual edit is cheaper than building a learning pipeline. |
Trade-offs
| Dimension | Effect | What to do about it |
|---|---|---|
| Quality | Improves on repeated task types as lessons accumulate. | Measure by version and keep a held-out set to catch regressions. |
| Latency | No effect on the live path if review runs offline. | Schedule the review step. Keep the live path read-only. |
| Cost | Adds storage, review calls, and replay runs. | Cap records per review and changes per week. Replay only a sample. |
| Complexity | Needs records, versions, a review step, and rollback. | Start with one change type, such as examples, and add more later. |
| Failure modes | Bad feedback teaches bad habits. A fix for one case can break another. | Require minimum evidence, human approval, and a replay check. |
Compared with related types
A reflexive agent critiques and revises its output inside one task, then forgets. A learning agent carries the lesson across tasks. The Reflexion paper sits between the two: it stores written self-reflections so later attempts improve. The memory pages show where the stored lessons live: episodic memory holds records of what happened, and procedural memory holds instructions and skills that can be updated.
A simple prompt edit by an engineer is the manual version of the same idea. The learning agent only earns its keep when edits would otherwise be frequent, slow, or easy to forget.
What this means for your role
Common mistakes
Further reading
- Types of AI agents: the hub page for all agent types.
- Reflexion (Shinn et al., 2023): agents turn task feedback into written self-reflections and keep them in memory to do better on later attempts, without changing model weights.
- Voyager (Wang et al., 2023): an agent in the game Minecraft that builds a growing library of skills stored as executable code and reuses them on new tasks.
- Russell and Norvig, Artificial Intelligence: A Modern Approach: the classic taxonomy that includes the learning agent.
- Evaluation and observability: how to score and trace the runs a learning agent depends on.
A learning agent is a feedback loop with a gate in it. Record honestly, review carefully, change small, and keep every version so you can go back.