C42 Updated 2026-06-20
Pillar 4 - Troubleshooting

Agent Memory Keeps Growing: Memory Bloat and Token Cost

Memory bloat happens when agents write too much, retrieve too broadly, and resend low-value context instead of curated source-linked evidence.

Agent memory bloat happens when the system writes too much and retrieves too broadly. The result is noisy recall and higher prompt cost. Fix it by tightening the write path, deduping repeated facts, storing source-linked summaries, limiting retrieval payloads, and measuring cost per query.

Last updated: June 20, 2026.

What causes memory bloat?

Memory bloat usually starts with a generous write policy. The agent stores raw turns, temporary tool output, duplicate decisions, and unsupported guesses. Retrieval then returns a large context pack, and the model pays to read material that should never have been durable memory.

OpenAI’s conversation state guide frames state as application-managed. That means the application must decide what to keep. If it keeps everything, the agent inherits the cost.

How does bloat affect quality and cost?

Bloat affects both:

Bloat symptomQuality effectCost effect
Duplicate memoriesAgent sees repeated factsMore tokens per answer
Stale memoriesOld facts compete with current factsMore debugging and retries
Raw transcriptsImportant decisions buried in chatterLarge context packs
Missing lifecycleDeleted/superseded facts still retrieveWasted retrieval and prompt spend
Broad scopeIrrelevant tenant or project facts appearLarger candidate sets

The memory cost calculator helps compare context-stuffing cost with memory retrieval credits. Use it after you know how much context your system sends.

How should you inspect bloat?

Measure:

  • Memory writes per session.
  • Duplicate facts by source and text similarity.
  • Retrieval candidates per query.
  • Final prompt tokens from memory.
  • Number of sources without citations.
  • Number of memories with no retrieval in the last review period.
  • Old facts without supersession state.

The MCP architecture docs explain server tools and resources. Your memory server should expose enough operational data to inspect these counts.

How do you reduce bloat?

Use a stricter write gate:

  1. Reject transient tool output.
  2. Require source or user confirmation for durable facts.
  3. Merge duplicates.
  4. Mark old facts superseded.
  5. Summarize long sources while keeping citation spans.
  6. Limit retrieval by tenant, library, type, and lifecycle.
  7. Review memories that never retrieve.

Do not solve bloat only by deleting old memories. Some old memories are valuable history. The right fix is lifecycle and retrieval discipline.

What should you store instead?

Store durable source-linked facts:

  • Decisions.
  • Stable project rules.
  • User preferences.
  • Current source summaries.
  • Corrections.
  • Supersession relationships.
  • Delete tombstones.

Keep working context, scratch notes, and local command noise out of long-term memory.

What is a practical cleanup cadence?

Review memory on a schedule tied to usage, not only calendar time. For a busy coding agent, inspect the most retrieved memories weekly and the never-retrieved memories monthly. For a low-volume assistant, review after major source imports or product policy changes.

The review should answer three questions: which memories are valuable, which are stale, and which are duplicates. Valuable memories stay. Stale memories get superseded or deleted. Duplicate memories get merged behind one source-backed current fact.

How do you keep cleanup safe?

Avoid blind pruning by age. An old architectural decision may still be the highest-value memory in the library. A recent transcript snippet may be worthless after the task ends.

Use lifecycle states instead:

StateRetrieval behavior
CurrentEligible for normal answers
HistoricalInspectable, but not preferred
SupersededShown only when history matters
DeletedExcluded from active retrieval

Those states let cleanup reduce prompt cost without destroying useful history. They also make retrieval behavior predictable when an agent asks why an older fact changed.

Track cleanup decisions as memories too when they affect future retrieval. “Archived duplicate onboarding snippets on June 20, 2026” is a useful audit note, not prompt context.

Read Memory needs a write path, What agent memory costs, and Context Rot. Use the failure-mode catalog when bloat appears with stale or contradictory answers.

Sources

Fig. 9 FAQPage schema / visible answers
FIG. 9

FAQ

Why does agent memory keep growing?

The write path is probably saving too much, deduping too little, or treating transient context as durable memory.

Why does memory bloat increase token cost?

Bloated memory retrieves larger payloads and often resends low-value context into the model prompt.

How do I inspect memory bloat?

Measure write volume, duplicate facts, retrieval payload size, repeated source snippets, and which memories enter the prompt.

How do I reduce memory bloat?

Add write gates, dedupe, lifecycle states, summaries with source links, retrieval limits, and cost checks.

NEXT

Build memory you can inspect.

Answer Engine gives agents a persistent, tenant-isolated memory layer via MCP, with source-aware recall and roadmap-labeled inspection work.