Series 1 of 4 · Agentic Stack · Bonus · Topic B03

Self-Improving Context

Bonus
In This Note You Will Learn
  • 01.How agents can learn to optimize their own context pipelines -- selecting better knowledge, loading more relevant memory, and choosing more effective tools from accumulated execution data.
  • 02.The tension between self-improvement and governance: a system that optimizes itself can optimize for the wrong metric.
  • 03.The production patterns already shipping: Claude Code's memory system, Notion AI's workspace learning, and how execution traces become training data for context assembly.

When Agents Start Editing Their Own Context

A developer at a fintech startup noticed something peculiar about Claude Code. On Monday, they asked it to fix a failing test in their payment processing module. The agent read CLAUDE.md, scanned the codebase, found the test, diagnosed the issue, and fixed it. 14 tool calls. 45 seconds. On Thursday, they asked it to fix another failing test in the same module. This time it went directly to the payment module -- skipping the broad scan. It checked memory and found a note from Monday's session. 6 tool calls. 18 seconds.

The second session was faster because the context was better. Not because the model was smarter -- the same model ran both sessions. The context pipeline was more efficient because it had learned from the first session's execution.

The Self-Improving Loop and Where It Goes Wrong

Throughout this deep dive, context has been designed by humans. Self-improving context adds a fourth mode: the agent learns what context works best through its own execution data, and adjusts its assembly strategy over time.

Self-improving context is the capability of an AI system to learn from its own execution traces -- what it retrieved, what tools it used, what succeeded, what corrections the user made -- and use that learning to improve future context assembly.

-- The definition

Think of it like a new employee's first month versus their sixth. In month one, they read every email, attend every meeting, check every document. By month six, they know which Slack channels matter, which documents are authoritative, which colleagues have the answers. They haven't gotten smarter. Their information diet has self-optimized through experience.

Fig 1. The Data Flywheel — and the Guardrails
Systems That Learn Their Own Context
Outperform Frozen Pipelines.
Four-node loop. Three guardrails on the trace-capture node.
agent execution tool calls · outcomes traces captured events · signals learned preferences what worked · per segment context assembly selects & orders inputs the data flywheel SELF-IMPROVING CONTEXT ⚠ feedback QC ⚠ drift detection ⚠ reset boundary
The loop is in soft purple. The three guardrails are in red — they are the safety constraints, not optional add-ons.

The governance tension. Self-improving context introduces a risk that static context doesn't: the system can optimize for the wrong metric without anyone noticing. Consider an agent that learns from user acceptance rates. If users accept 95% of outputs mentioning "premium plan" pricing, the system might learn to prioritize premium documentation -- even when the customer is asking about a free tier.

Watching the System Learn (and Catching It When It Mislearns)

The cold-start problem. Self-improving context is powerful for mature deployments but useless for new ones. The first-session experience is the worst experience -- which is also the evaluation session for the buyer. The ramp time from new customer to self-improved context is typically 2-4 weeks.

Data isolation at enterprise scale. When Agent A at Customer 1 learns effective retrieval patterns, that learning must be strictly isolated from Customer 2. In multi-tenant systems, context improvements are per-tenant assets -- leaking optimization data between tenants is a data breach.

!

The Trap

Trusting self-improvement without verification.

Quality metrics go up. Response times go down. The team celebrates and reduces monitoring. Then a model version changes, and the learned preferences -- tuned for the old model's reasoning patterns -- actively degrade performance with the new model.

The fix: treat self-improvement as a hypothesis, not a fact. Run periodic A/B tests between the learned pipeline and the baseline. Self-improving context without continuous evaluation is self-deluding context.

The Flywheel and the Guardrail

Self-improving context creates a data flywheel that becomes a competitive moat. More usage leads to more execution traces, which leads to better context assembly, which leads to better outcomes, which leads to more usage. The flywheel takes weeks to start but compounds over months.

Fig 2. The CSM QBR — Three Sessions
The Pipeline Learned
What Good Looks Like.
Same task, three weeks. Context shrinks, quality climbs, segments emerge.
Week 1 · cold start
14,200 tokens · quality score 62/100
knowledge
constitution
equipment
tracks
template
u
Week 4 · early learning
9,400 tokens · quality score 81/100
knowledge
constitution
equipment
tracks
template
u
Week 12 · segment-aware
avg 6,200 tokens · quality score 94/100
High-risk enterprise · 7,800 tok
knowledge
constitution
equipment
tracks++
tmpl
Healthy growth · 4,600 tok
knowledge
const
equip
tracks
tmpl
The context pipeline learned what good looks like — for each account segment, different.

Remember This

1. Self-improving context means the agent learns from its own execution traces to improve future context assembly. The mechanism is real and already shipping in Claude Code, Copilot, and Notion AI.

2. The governance tension: systems that optimize themselves can optimize for the wrong metric. Drift detection, feedback quality control, and reset boundaries are the three governance patterns.

3. Self-improving context creates a data flywheel that becomes a competitive moat. More usage leads to better context leads to better outcomes leads to more usage. Competitors can't replicate the accumulated execution data.

References

1. Claude Code: Best Practices for Agentic Coding -- Anthropic

2. Building Effective Agents -- Anthropic Engineering Blog

3. GitHub Copilot Workspace -- GitHub Next

4. EU AI Act -- Right to Explanation Requirements

Previous Topic Back to the Deep Dive