Learning & adaptation: improve from feedback
Let the agent improve at runtime by storing scored outcomes and retrieving the wins as few-shot examples and the failures as warnings — no retraining required.
What it is
Learning and adaptation is how an agent gets better at a task at runtime — from its own outcomes — without retraining the base model. The weights stay frozen. What changes is the context you feed the model on the next turn.
Three common levers:
- Few-shot selection: pull the examples that worked for similar inputs into the prompt.
- Reflection traces: after a run, write down what went wrong, then read it back next time.
- Preference signals: thumbs-up, edits, and corrections that re-rank future behavior.
Think of it as the agent keeping a notebook, not going back to school.
When to use it
Reach for it when the same kinds of tasks recur and you have a signal for what "good" looked like:
- Repeated workflows where past successes are a template for the next one (support replies, code fixes, extraction).
- Tasks with a verifiable outcome — tests passed, user accepted the answer, the tool returned clean.
- Domains that drift, so yesterday's good example beats a static prompt.
It leans on memory to persist what's learned and pairs naturally with reflection.
Don't bother for one-shot or stateless tasks, or when there's no honest outcome signal — you'll just memorize noise. For correctness rules that must never bend, use guardrails, not learning.
How it works
The loop is act, judge, store, retrieve — and retrieval is the part that actually changes behavior.
- After a run, score the outcome (a test result, a user edit, an LLM judge) and write a record: input, what you did, what happened.
- Example: store
{task, plan, result: "failed — wrong date format", fix: "use ISO-8601"}keyed by an embedding oftask. - On the next similar task,
retrieve(top_k)the closest records and inject the wins as few-shot examples and the failures as "avoid this" notes. - The model now conditions on lived evidence instead of a frozen prompt.
Keep the store small and ranked; relevance beats volume.
Watch out for
- Poisoned memory: one bad outcome stored as a "good" example teaches the wrong lesson forever. Gate writes on a real success signal, not just task completion.
- Stale wins: an example that worked last quarter can mislead after the domain shifts. Expire or down-weight old records.
- Feedback loops: the agent retrieves its own past output, reinforces it, and drifts. Mix in ground-truth examples and watch for collapse via observability.
- No honest signal: if your "reward" is the model grading itself unchecked, you're amplifying bias, not learning. Anchor scoring to something external.
Related patterns
Memory: what the agent keeps between turns
An agent's memory has two layers — the short-term context window and a long-term store you retrieve from — and the skill is deciding what to keep, summarize, and forget.
Reflection: let the agent critique its own output
Reflection runs your agent twice — generate, then critique against explicit criteria and feed the fixes back — so a weak first draft becomes a stronger final answer.
Evals: gate on recall, not vibes
Make the metric deterministic before you trust any number. Gate releases on recall over a fixed must-handle set; keep the LLM judge off the gate.