Why Agent Token Use Keeps Rising: Long-Term Memory and Context Governance
Rising token use does not, by itself, prove that an agent is stronger or that long-term memory is working. This article explains how to separate raw interaction logs from usable memory, extract and compress context without losing decision-critical facts, recall history within clear boundaries, control cost across the full execution chain, and judge memory by quality, cost, and governance—not by how much the system stores.
1. What Does Rising Token Use Actually Mean?
When an agent’s token consumption climbs quickly, the easy explanations are that more people are using it, the system has become more capable, or long-term memory has started to help. From an engineering perspective, none of those conclusions is justified without additional evidence.
A token is the basic unit a model uses to process text. Completing one task usually means more than reading the user’s question. The agent also loads system instructions, prior messages, retrieved material, and tool results. During execution it may plan, call tools, check results, and retry across multiple turns. One user request can therefore map to several model calls.
A rise in total consumption can come from at least four kinds of change:
- More users, and therefore a larger volume of tasks
- More complex individual tasks, with more execution turns
- Longer input context, including more repeated information
- Failed calls or plans that drift, which trigger extra retries
Higher consumption can mean business growth, or it can mean worse resource efficiency. Even a consumption ranking is hard to interpret until the measurement scope, time window, and whether inputs, outputs, cache hits, and failed requests are included are all explicit. Without that, rankings say little about the real capability of different systems.
For developers, the more useful question is not who spends the most. It is: how many resources does one successful task require, and do those resources actually improve the outcome?
2. Saving Interaction Logs Is Not the Same as Having Long-Term Memory
Many agents store interaction records locally or in a server-side database. Typical fields include session IDs, user IDs, message bodies, model configuration, system-instruction versions, tool-call parameters, tool results, and execution status.
Those records have clear engineering value: troubleshooting, task recovery, quality analysis, and audit trails. Three ideas still need to be kept apart:
First, persistent storage.
Writing data so it still exists after the process ends.
Second, searchable history.
Finding older records relevant to the current task by time, keywords, semantics, or structured filters.
Third, usable long-term memory.
Turning history into facts, preferences, constraints, or experience that can keep shaping later decisions—and keeping that material valid over time.
The three are not equivalent. A database full of conversations does not mean the system reads them on every turn, or that it can tell which pieces are worth using.
Saving history also does not prove that an agent can “evolve itself.” Improving behavior through retrieval and reuse of experience usually does not mean model parameters have changed. The more accurate description is that the system uses external memory to change the inputs to later reasoning.
Growing records are not an inevitable path to unbounded growth either. Scale depends on retention windows, archival policy, cleanup rules, and task volume. What needs governance is whether growth is predictable, whether the data is valuable, and whether storage and processing costs stay inside budget.
3. Separate Raw Records from Long-Term Memory First
The first design principle of a long-term memory system is that one database should not carry every responsibility.
A clearer architecture can be split into four layers.
1. Raw event layer: keep traceable evidence
This layer records user messages, tool results, and important state changes for audit, recovery, and review.
Raw events should include source, time, session scope, and permission information. For large tool outputs, store a reference to the full content plus a short description, so later reasoning does not have to reread the entire body every time.
Different data should have different retention periods. Troubleshooting logs, business facts the user has confirmed, and temporary tool results do not need the same lifecycle.
2. Working-context layer: serve the current task
Working context includes the current goal, completed steps, open questions, and the recent messages that are actually needed.
Its job is to keep the task continuous, not to hold the user’s entire history. When the task ends, part of this context can be archived. Only a small amount of information with lasting value should move into the memory layer.
3. Long-term memory layer: keep stable, reusable information
Content that is usually worth keeping long term includes:
- Expression preferences the user has explicitly confirmed
- Stable technical constraints of a project
- Confirmed business rules and key decisions
- Reusable solutions and lessons from failures
- Task state that must continue across sessions
This information should be structured as far as possible. A project constraint should not only say “do not change existing interfaces.” It should also record which project it applies to, who confirmed it, when it took effect, and whether it has already expired.
4. Retrieval-index layer: help locate information
Indexes speed up lookup. They can include full-text indexes, semantic indexes, and structured filter fields.
An index is an aid for finding information. It should not be the only source of truth. When a raw record is deleted, a memory is revised, or permissions change, the related indexes must be updated as well.
This split avoids two common failures: dropping audit evidence just to shrink context cost, and feeding the entire history back into the model just to keep every piece of evidence.
4. Memory Extraction Cannot Rely on Keywords Alone
Keyword matching is good for finding explicit terms. It is not enough to judge long-term value.
If a user says “do not change the database schema this time,” the phrase “this time” limits the scope. A system that only remembers “do not change the database schema” may apply a temporary request to future tasks by mistake.
By contrast, “this project must keep compatibility with the old version” may be a constraint every later plan has to follow, even if the wording contains no frequent keywords.
Memory extraction should at least judge these dimensions:
- Type: fact, preference, task state, temporary instruction, or inference
- Scope: global, user, project, session, or a single task
- Evidence: explicit user confirmation, tool observation, or the model’s own inference
- Lifetime: long-lived, due for periodic review, or invalid after the task ends
- Sensitivity: whether it includes personal data, credentials, or restricted data
- Reuse value: whether a future task is likely to need it again
Conclusions produced by the model need extra care. The fact that an agent once said something does not mean it has been verified. If an unverified inference is written into long-term memory and later treated as fact, errors reinforce themselves.
A safer flow is:
candidate extraction → type and scope checks → deduplication and conflict detection → confirmation when needed → write to memory.
High-risk constraints—permissions, finance, production changes, and similar cases—should prefer explicit confirmation over automatic inference.
5. The Goal of Context Compression Is to Keep the Basis for Decisions
Context compression is not simply turning long text into short text. It is keeping, inside a limited budget, the information that will affect later decisions.
A useful task summary should at least answer:
- What needs to be finished now
- Which limits must not be broken
- Which facts have already been confirmed
- What has been tried, and what the results were
- Which problems are still open
- What evidence or action the next step needs
A troubleshooting summary that only says “configuration was checked; the problem remains” is short, but almost useless to reuse. A better summary states which configuration was checked, which hypotheses were ruled out, and why the next step should inspect a particular part of the system.
Compression also accumulates distortion. If each new summary is only a summary of the previous summary, detail is lost step by step, and temporary guesses can harden into settled conclusions.
Practical controls include:
- Keeping references to original evidence for key conclusions
- Separating confirmed facts from hypotheses that still need verification
- Storing important constraints in their own structured fields
- Periodically rebuilding summaries from raw events
- Recording a version and generation time for each summary
Do not judge compression only by how much shorter the text became. Check whether key constraints survived, whether the task can continue, and whether the summary added judgments that were not in the source.
6. History Recall Needs Relevance and Boundaries
Stuffing large amounts of past context back into the prompt does not automatically improve results. Irrelevant content can distract the model. Outdated content can cause wrong decisions. Content from another user can leak data.
A more reliable recall flow usually has three stages.
1. Filter scope first
Start by selecting candidates according to user, project, permissions, and data status.
Permission isolation should be enforced at retrieval time. It should not depend only on a prompt that tells the model “do not leak.”
2. Then look for relevant information
Keyword search, semantic search, and structured queries can be combined.
Keyword search fits exact terms, identifiers, and error messages. Semantic search fits similar needs expressed in different wording. Structured queries fit project ownership, validity windows, and status filters. Each has strengths. No single method covers every case.
3. Finally choose what enters the context
Rank candidates by relevance, freshness, trustworthiness, and value to the current task, and remove duplicates.
If historical items conflict, do not simply keep the one with the highest similarity. Check whether a newer explicit confirmation exists, whether an old rule has been retired, and whether different items apply to different scopes.
Retrieved results are data still waiting to be judged. They should not be promoted automatically into high-priority instructions. Old web pages, documents, and tool results can contain misleading content. Successful recall does not authorize them to override current permissions and safety rules.
7. Token Cost Control Should Cover the Whole Execution Chain
Model input for a task can usually be broken down as:
input tokens ≈ system instructions + current request + recent messages + recalled memory + tool results
Total task consumption is the sum of inputs and outputs across all calls, including retries and intermediate steps. Actual cost also depends on the billing rules of the service in use. Token counts are not a single uniform price.
When optimizing, find the parts that dominate cost first. Do not blindly shorten the user’s input.
1. Cut low-value replay of history
History that has already been turned into a reliable summary does not need to be carried in full on every turn. Key constraints should still be kept, with a way to look up the evidence when needed.
2. Control the size of tool results
Tool results can first return the necessary fields, a summary, and evidence references. Read the full detail only when verification requires it.
Do not truncate blindly. If the cut removes the error cause or a critical record, the tokens saved may be paid back in extra retries.
3. Set stop conditions for execution
Put limits on call count, repeated attempts, and total budget. When a limit is hit, return the current conclusion, what is still unfinished, and what needs a human decision, instead of looping without progress.
4. Match reasoning effort to task risk
Format conversion, information extraction, and complex planning do not need the same level of reasoning. Tiered handling is reasonable only if evaluation shows that the cheaper path still meets the quality bar.
5. Reuse stable content when it is safe to do so
Repeated read-only queries and stable reference material can be cached or reused. Cache entries must respect expiry, permissions, and data change. Do not reuse results that are stale or that belong to another user.
8. Use an Evaluation Loop to Judge Whether Memory Works
Whether long-term memory improves a system cannot be decided by a feeling that it “understands the user better.” Quality, cost, and risk need to be measured together.
Quality metrics can include task success rate, rate of missed key constraints, rate of incorrect memory citations, and correctness after information has been updated.
Cost metrics can include average tokens per successful task, number of call rounds, latency, and growth of long-term storage.
Governance metrics can include writes of sensitive information, out-of-scope recall, completion of deletions, and handling of expired data.
Test sets should cover boundary cases: a user changing a preference, the same term meaning different things in different projects, an old approach replaced by a new rule, a wrong conclusion already in history, and a user asking for specific information to be deleted.
Under the same task conditions, compare three setups—“no long-term memory,” “replay history directly,” and “structured memory plus retrieval”—to see where the gain actually comes from. Keep the model, tools, and task conditions as consistent as possible, so a change in model capability is not mistaken for an effect of the memory mechanism.
9. The Real Challenge Is Memory That Can Be Explained, Updated, and Deleted
As interaction data accumulates, storage cost is only one problem. The deeper question is whether the system knows where a piece of information came from, whether it may still be used, whom it applies to, and when it must stop being used.
Mature memory governance should provide provenance, change history, expiry, and deletion. When a user withdraws information, the original message is not enough. Related summaries, memory entries, indexes, and caches need to be governed as well. Data in backups should follow an explicit retention and restore policy.
When building an agent, “remember more” should not be the only goal. A better goal is to use the least information that is still sufficient for the current task, follow the latest valid constraints, produce a result that can be checked, and keep the whole process observable and controllable.
What matters about rising token use is not the number itself. It is whether that spend turns into a higher task completion rate, less repeated communication, and more reliable decisions. Only when storage, extraction, compression, recall, safety, and evaluation are connected does long-term memory stop being an ever-growing pile of history and become an engineering capability that can be maintained.
