13 min read

Self-Baking: Why Your AI Agent Must Learn to Digest Its Own Context

Bigger context windows look like memory. They are mostly appetite.

An agent can swallow 200,000 tokens, complete a task, and still wake up tomorrow with the intellectual habits of a goldfish wearing a very expensive GPU. The industry keeps treating storage as if it were learning. It is not. A transcript is not judgment. A log file is not understanding. A pile of past interactions, no matter how searchable, is still just a pile until the agent turns it into something it can reuse.

That missing step needs a name. Self-baking fits.

Memory is not the same thing as learning

Self-baking is the capacity of an agent to transform raw context into structured, reusable knowledge. The distinction sounds small. In practice, it changes the entire design of the system.

Most agents today are built around accumulation. They collect chat history, documents, tool outputs, code diffs, issue threads, stack traces, and notes. Then they stuff some subset of that material back into the prompt during the next turn. This works surprisingly well for short stretches. It feels like continuity. It can even look smart.

But a large window only preserves access, not abstraction.

Humans do something more interesting. We do not walk around replaying every minute of yesterday in lossless detail. We compress. Episodic memory becomes semantic memory. Repeated experience becomes habit. A hundred concrete moments slowly harden into a rule of thumb, a concept, a bias, sometimes a superstition. The raw footage matters, but the useful part is what survives digestion.

Agents need the same metabolism.

That means turning raw context into summaries, summaries into facts, facts into schemas, and sometimes schemas into vectors or other compressed representations. The exact format matters less than the direction of travel. The system should become less dependent on the original transcript over time, not more.

If that sounds obvious, notice how many agent stacks still stop at “store everything in a database and retrieve top-k.”

The hidden tax of raw context

The immediate problem is scale. Context windows are finite, retrieval is noisy, and old information rots. Yet the deeper problem is behavioral.

An agent without self-baking tends to repeat its own life. It rediscovers conventions it already encountered. It misses team preferences buried inside past tickets. It reopens solved questions because the answer lives in a blob of prior conversation nobody thought to normalize. In codebases, this shows up as the same architectural mistakes resurfacing in new pull requests. In research agents, it appears as duplicated reading and weak synthesis. In support systems, it becomes that maddening feeling that the assistant “knows” your history but somehow never learns from it.

We have seen this movie before in software. Early data systems mistook retention for intelligence. Then analytics taught us the hard part was not collection. It was modeling. Agents are replaying that lesson with tokens.

There is also a cost curve here. Raw context gets more expensive as it grows because retrieval, ranking, and prompt assembly all become harder. Structured knowledge gets cheaper because it can be composed, filtered, validated, and updated. An unfiltered archive behaves like a basement. Everything is technically there. Good luck finding the one screwdriver you need.

The human analogy is useful, up to a point

The human comparison helps because it explains what kind of transformation matters.

When a developer fixes the same flaky test three times, something shifts. The first memory is episodic: a failed CI run, a strange timeout, a workaround. The fifth time, it becomes semantic: “this test is timing-sensitive when the fixture boots before the cache is warm.” Later still, it becomes procedural: add a readiness gate before the assertion. The knowledge is no longer tied to one incident.

An agent can follow a similar path.

A session transcript might contain a debugging exchange, several shell outputs, and a final patch. A baked summary can capture the real lesson: this service fails on cold start if environment variables load after dependency initialization. A fact extractor can store that relationship explicitly. A schema can attach it to the service, affected files, and remediation pattern. A vector can then support fuzzy retrieval when the next failure looks similar but not identical.

The analogy breaks if we get mystical about it. Agents do not “understand” experience in a human sense. Their compression mechanisms are statistical and symbolic, not lived. Still, the design principle holds: useful memory is transformed memory.

Four self-baking patterns are emerging

Different teams are solving this in different ways. None is perfect. Each represents a trade-off between simplicity, structure, interpretability, and scale.

Raw context plus natural-language summaries

This is the most common pattern because it is easy to bolt on. Systems like Claude Code and Gemini CLI workflows often keep substantial raw history, then periodically generate summaries of what happened. The summaries may include recent goals, files touched, constraints discovered, unresolved issues, and conventions inferred from the work.

The benefit is obvious. Natural language is flexible. You do not need to define a schema up front. The model can summarize whatever seems important, and humans can read the result without special tooling. For coding agents, this often goes surprisingly far. A good summary can preserve intent across long sessions better than a naive retrieval pipeline.

The downside arrives later. Free-text summaries are slippery. Retrieval gets fuzzy because there is no guaranteed shape. Merge quality depends on the model’s phrasing. Contradictions are hard to detect. If the agent once summarized “team prefers explicit interfaces” and later writes “light abstraction is acceptable,” you need another model pass to decide whether that is evolution, nuance, or drift.

This pattern is a strong first step. It rarely becomes the final one.

Raw context plus fixed schema extraction

Some teams move in the opposite direction and extract key facts into predefined structures. Code review systems like CodeRabbit point in this direction: entity maps, task trees, event records, file-level observations, dependency graphs, and policy checks. The agent still has access to raw context, but the durable memory lives in typed fields.

This makes retrieval much sharper. You can ask for all decisions touching a module, every recurring lint violation in a repo, or unresolved tasks related to authentication. Structured memory also makes it easier to diff changes over time. A schema lets the system know what has been learned, what is uncertain, and what conflicts with previous facts.

The price is rigidity. The minute your schema misses a class of knowledge that turns out to matter, you face the least glamorous problem in modern software: maintenance. New fields appear. Old records need migration. Edge cases grow teeth. The clean ontology from the design doc starts to resemble a junk drawer with protobuf definitions.

Still, for narrow domains with clear objects and rules, fixed schemas are powerful. Compliance, code review, workflow orchestration, and customer support all benefit from memory that behaves like data rather than prose.

Raw context plus progressive vector compression

Another path uses embeddings or hierarchical compression to produce dense representations of prior context. Research around H-MEM and related memory architectures explores this territory: encode chunks, pool them progressively, and maintain multiscale semantic summaries that can be searched or conditioned on later.

This approach shines when the corpus is huge and exact wording matters less than conceptual similarity. It is compact. It scales well. It can surface related past episodes even when the surface form has changed. For research agents working through large document sets, this can be the difference between vague repetition and actual thematic continuity.

But vector memory has a familiar problem: you often cannot tell what, exactly, has been retained. It is semantically useful and operationally murky. If a coding agent retrieves an embedding-neighbor because two incidents “feel alike” in latent space, that may be enough for generation. It is less satisfying for auditability, debugging, or policy enforcement. Black-box compression is memory with bad bedside manners.

Vectors are excellent servants. They are risky sovereigns.

Hierarchical memory architectures

The most ambitious pattern combines several layers: raw logs, working memory, episodic records, semantic knowledge, and sometimes a learned retrieval policy between them. Research systems such as Tongyi’s LeadResearcher suggest where this is going, especially for deep research and ultra-long contexts.

This is the closest analogue to how a serious agent should behave. Recent details remain nearby. Important episodes become explicit records. Stable facts graduate into durable knowledge. The system can use different retrieval strategies depending on the task. A code fix may need raw stack traces. A planning step may need only semantic constraints. A literature review may want episodic citations plus conceptual clusters.

The complexity is substantial. You are no longer building a clever prompt stack. You are orchestrating a memory system with triggers, merge logic, confidence scores, decay rules, and provenance. That is real engineering. It is also where many teams discover that memory quality matters more than memory volume.

Self-baking is an architectural loop, not a feature

People often picture this as one extra summarization call after each session. That is too shallow.

A real self-baking system needs at least five moving parts. It ingests raw context. It decides when baking should occur. It generates compressed representations. It merges those representations into durable memory. Then it retrieves the right layer for the next task. Each step can fail differently.

Triggering is more important than it sounds. If you bake constantly, you waste tokens and amplify noise. If you bake rarely, the raw context grows unwieldy and key lessons stay trapped in transcripts. Good triggers are usually event-based: after a pull request merge, after a bug is resolved, after a research subgoal is completed, after a user corrects the agent twice on the same preference. Threshold-only triggers are a blunt instrument.

Merging is where systems either mature or become haunted. Imagine two baked memories:

  • “Use dependency injection in all new services.”
  • “Small internal scripts may instantiate clients directly.”

These are not necessarily contradictory. They might represent scope. Or a policy change. Or a one-off exception that should not generalize. A useful memory layer has to preserve provenance, confidence, and temporal context. Otherwise the agent accumulates folklore.

For that reason, self-baking should not aim to produce a single blob called “knowledge.” It should produce artifacts with types. Preference. Fact. Decision. Pattern. Open question. Exception. Deprecated rule. The agent then has a fighting chance of using the right memory in the right way.

A simple implementation is already within reach

The basic pattern is straightforward enough to sketch in a few lines:

class SelfBakingMemory:
    def __init__(self):
        self.raw_events = []
        self.knowledge = {}

    def add_event(self, event):
        self.raw_events.append(event)
        if self.should_bake(event):
            self.bake()

    def should_bake(self, event):
        return event.type in {"pr_merged", "task_closed", "user_correction"}

    def bake(self):
        summary = llm.summarize(self.raw_events)
        facts = llm.extract_facts(summary)
        merged = merge_with_provenance(self.knowledge, facts)
        self.knowledge = merged
        self.raw_events = keep_recent(self.raw_events, n=20)

The code is simple because the hard parts are hidden in the names. extract_facts needs type discipline. merge_with_provenance needs conflict handling. keep_recent needs a retention policy. Even then, this sketch captures the important idea: raw events are not the destination. They are feedstock.

In practice, useful systems add a few guards. Store source links so every baked fact can be traced back to logs, diffs, or documents. Keep confidence scores, because model extraction is never perfect. Distinguish accepted knowledge from candidate knowledge when the system is uncertain. And let humans edit the durable layer. Memory without correction becomes mythology with autocomplete.

Coding workflows already contain the ingredients

If you spend time in agent-assisted coding, you can see self-baking hiding in plain sight.

Your logs are raw context. AGENTS.md is baked guidance. A hand-written note like “after fixing auth middleware, update the route contract doc” is durable memory. Teams already do this manually whenever they update a runbook after an incident or add a convention to contributor docs after reviewing the same mistake for the tenth time.

The opportunity is to make that loop systematic.

Suppose your coding agent works through tasks during the day. It reads issue threads, opens files, runs tests, applies patches, and gets corrected by a human reviewer. On merge, a baking job can synthesize several kinds of durable memory: repository conventions, known failure modes, architecture decisions, recurring code smells, and unresolved questions worth resurfacing later. Those artifacts can live in INSIGHTS.md, PATTERNS.md, or a small structured store exposed through an MCP server.

Now the next session starts differently. The agent does not just reload yesterday’s transcript. It begins with refined constraints and patterns extracted from many sessions. That means less token waste, fewer repeated mistakes, and faster alignment with how the team actually builds software.

This matters especially in “vibe coding” environments, where the pace is fast and much tacit knowledge never reaches formal documentation. In those settings, the agent is constantly bathing in local conventions that disappear unless someone distills them. Self-baking turns ambient tribal knowledge into something portable.

The real challenge is deciding what deserves to harden

Not every event should become memory. Some details are noise. Some are local hacks. Some are temporary conditions that should expire. If the agent bakes everything, it becomes a hoarder with an excellent filing system.

So the quality of self-baking depends on selection.

The durable layer should favor information with reuse value. Repeated user preferences. Stable architectural decisions. Patterns linking symptoms to causes. Failure modes with verified fixes. Domain concepts that appear across tasks. Constraints that affect planning, not just one response.

It should be skeptical of transient state. Random stack traces. Temporary branches. Half-formed ideas from exploratory work. The fact that a developer bypassed a failing test once at 2:13 a.m. does not mean the repository now endorses chaos as a methodology.

This is where model judgment can help, but only if the system asks a concrete question. “Summarize the session” is too broad. Better prompts ask: which decisions were made, which facts were verified, which patterns recurred, and what should influence future tasks? Memory improves when extraction is opinionated about utility.

The competitive edge will come from digestion, not appetite

For the next generation of agents, context window size will still matter. Bigger windows are useful. They reduce the need for awkward truncation. They let the model see more of the workspace at once. They make some workflows feel smoother.

But raw capacity is heading toward commodity. Everyone gets a bigger bucket eventually.

The harder advantage is turning experience into reusable structure. That is what makes an agent better in month three than in minute three. That is what lets it carry standards across sessions, spot recurring problems before a human points them out, and operate inside a codebase or organization with something closer to continuity than recall.

An agent that only stores is like a company that records every meeting and learns nothing from them. An agent that bakes builds working memory into institutional memory. That shift sounds incremental. It is not. It marks the line between systems that merely persist and systems that accumulate competence.

End of entry.

Published April 2026