09. Advanced Concepts
Self-Reflection, Learning and Adaptation
Self-reflection, learning, and adaptation let agents critique their own drafts, plans, and tool results, then revise under budgets β storing durable lessons in memory and improving prompts/evals offline. Reflection is not vibes: use rubrics, tests, and stop rules so critique loops do not thrash or invent false confidence.
What you will learn
- Define reflection vs learning vs adaptation clearly
- Design a draft-critique-revise loop with stop rules
- Map within-run, memory, prompt/eval, and weight-level adaptation
- Avoid reflection failure modes (infinite critique, fake confidence)
- Answer interview questions with short, solid answers
Definition
Self-reflection is an explicit critique step after an action or draft: check quality, correctness, policy, or evidence before accepting the result. Learning stores what went wrong or right (often as episodic/semantic memory). Adaptation changes future behavior β retry/replan now, retrieve lessons later, update prompts/evals, or rarely fine-tune weights.
Patterns like Reflexion-style verbal feedback, critic agents, and verifier tools all sit under this umbrella when they are budgeted and measurable.
Introduction
This lesson (#4 in Advanced Concepts) follows Long-Horizon Planning. Plans fail in the real world; reflection turns failures into better replans instead of blind retries.
Next: Autonomous Research Agents.
Why it matters
- First drafts and first retrieves are often wrong
- Tool errors need diagnosis, not identical repeats
- Long-horizon runs improve when lessons persist
- Evals alone are offline β reflection helps online
- Unbudgeted self-talk burns tokens without gains
Reflection loop
Keep critique operational: pass/fail against criteria.
- Draft - answer, plan step, or tool outcome
- Critique - rubric, unit tests, schema, groundedness check
- Revise - fix, replan, or escalate to HITL
- Stop - pass, max retries, or escalate
- Log critique reasons on the trace span
Learning signals
- Verbal lessons: short βwhat failed / what to tryβ notes
- Structured errors: error_class, retryable, root cause
- Eval scores sampled from production traces
- User feedback thumbs and corrections
- Store as memory with source and confidence β not silent prompt lore
Adaptation levels
Climb the ladder only as far as evidence justifies.
- Within-run - retry tool, rewrite query, replan step
- Cross-session memory - remember pitfalls and prefs
- System prompts / few-shots / routers - versioned releases
- Eval harness - catch regressions before ship
- Fine-tuning / RL - expensive; use when data and process exist
Design rules
- Rubrics beat βthink harderβ prompts
- External ground truth when available (tests, compilers, schemas)
- Separate critic role or tool from the actor when bias is high
- Cap reflection retries; escalate instead of looping
- Do not treat self-confidence as verification
- Persist only validated lessons to long-term memory
Map to earlier modules
- Long-horizon replan consumes reflection output
- Memory lesson = where lessons are stored
- Agentic RAG critique = reflection on evidence sufficiency
- Observability traces feed offline learning
- Next: research agents that reflect across many sources
Failure modes
- Infinite critique loops that never ship an answer
- Critic and actor sharing the same blind spots
- Writing false lessons into memory (poisoning future runs)
- Skipping verifiers because reflection βfelt goodβ
- Fine-tuning on noisy online chatter without curation
Program / implementation notes
Add a critique step with a JSON rubric (pass, issues[], suggested_fix). Retry up to N times; on final fail, escalate or refuse. Write a one-line lesson to memory only when pass becomes true after a failure.
- Wire reflection spans into your tracer
- Next: Autonomous Research Agents
Advantages and limitations
- Advantage: higher quality without always needing a larger model
- Advantage: turns failures into durable procedural memory
- Advantage: fits planning and RAG critique naturally
- Limitation: extra latency and token cost
- Limitation: weak rubrics produce theater, not quality
- Limitation: adaptation can amplify biases if unchecked
Key points
- Reflect = critique against criteria; learn = store lessons; adapt = change next behavior.
- Use draft-critique-revise with hard stop rules.
- Prefer external verifiers when you can.
- Adapt first within-run and via memory; fine-tune last.
- Do not confuse self-confidence with correctness.
- Trace and eval reflection like any other agent step.
FAQs
Is reflection the same as chain-of-thought?
No. CoT reasons toward an answer. Reflection critiques an already produced draft/plan/result against a rubric, often in a second pass or role.
When skip reflection?
For low-risk, high-confidence, single-step tasks where latency matters and evals already pass β reflection is a tool, not a tax on every call.
Actor-critic with one model?
Possible, but same-model critics share blind spots. Use tools/tests or a separate critic prompt/model for important paths.
How does this relate to fine-tuning?
Online reflection/memory handle most adaptation. Fine-tuning is offline weight change after curated datasets prove the gap.
Interview questions
- What is agent self-reflection?
Answer An explicit critique of a draft, plan, or tool outcome against criteria, used to decide whether to accept, revise, replan, or escalate.
- How do learning and adaptation differ?
Answer Learning records durable lessons from outcomes; adaptation applies those lessons (or prompt/eval/weight changes) so future behavior improves.
- Describe a safe reflection loop.
Answer Draft β critique with rubric/verifier β revise if failing β stop on pass, max retries, or HITL escalate β with traces and budgets.
- Name adaptation levels from fast to slow.
Answer Within-run retry/replan, cross-session memory, prompt/eval updates, then fine-tuning or heavier training.
- What is a common reflection failure?
Answer Unbounded critique loops or trusting the modelβs self-confidence without external checks, wasting tokens and still shipping errors.
- How should lessons be stored?
Answer As structured memory with source, confidence, and ACL β written only when validated β so future retrieves do not amplify noise.
Related topics
Practice task
Complete each numbered practice step in a notebook or doc before opening the next lesson.
- Write a JSON rubric for βsupport answer qualityβ (5 pass/fail checks).
- Design a max-2 reflection loop for that rubric including escalate behavior.
- Specify what lesson gets written to memory after a failed-then-fixed run.
- List 3 verifiers that are better than pure LLM self-critique for coding agents.
- Answer interview questions 1, 3, and 5 in two sentences each.