Why AI Agents Burn So Many Tokens: Long-Term Memory and Cost Governance in Practice
This article explains why rising token consumption is a poor proxy for agent quality, and what actually drives cost: repeated history in context, oversized tool results, weak retrieval, and missing stop conditions. It walks through the difference between storing transcripts and having real long-term memory, why databases keep growing, how to layer memory into working, episodic, factual, and procedural types, how summarization and retrieval cause silent information loss, and how to break cost down along the execution chain. It closes with practical guidance on execution-state tracking, idempotency, observability metrics, regression testing, and data minimization for teams moving from a working prototype to a reliable system.
1. What Rising Token Consumption Actually Tells You
When token consumption in an agent system climbs quickly, the easiest conclusion is that more people are using it, the tasks have become more complex, and the system has grown more capable.
All of those explanations are possible, but consumption volume alone proves none of them. Even when some kind of consumption ranking exists, you first need to define the measurement scope, the time window, which models are covered, and how the numbers are calculated. Without that, comparisons between different systems are not meaningful.
More importantly, token consumption reflects the scale of computation, not the quality of task completion. For the same task, one agent may finish in two model calls, while another may need a dozen calls because retrieval was inaccurate, the plan was revised repeatedly, and tools were executed over and over. The second one consumes more but does not necessarily deliver more value.
So when discussing high-consumption agents, the questions worth asking are not “how much was used” but:
- Which calls produced real progress?
- Which historical information deserves to enter the current context?
- Which tool results are being read or regenerated repeatedly?
- Is the system completing tasks reliably within a limited budget?
All of these questions point to the same set of foundational capabilities: memory management, context organization, execution control, and runtime observability.
2. Saving Every Conversation Is Not Long-Term Memory
Many agents write interaction records into a local or remote database. Typical records include session identifiers, user identifiers, model configuration, snapshots of system instructions, message content, tool call parameters, and tool return values.
This design solves the problem of whether records can be retained. It is valuable for session recovery, troubleshooting, audit trails, and runtime evaluation, but it does not by itself prove that the system has effective long-term memory.
Three layers need to be distinguished:
Layer 1: persisted records. The system stores what happened, but those records do not necessarily participate in later reasoning.
Layer 2: retrievable information. The system can search historical records for content relevant to the current task, but what it finds may be incomplete, inaccurate, or no longer valid.
Layer 3: task-relevant memory. The system can identify which information is worth keeping, judge its scope and validity period, and deliver it to the model at the right moment in the right form.
Only a closed loop of extract, store, retrieve, verify, use, and update turns historical data into a stable task capability.
Likewise, storing history does not mean the model’s parameters have changed. The claim that a system “understands the user better the more it is used” may simply mean that runtime memory was consulted, such as user preferences, existing constraints, and prior cases, rather than the model itself being trained. Engineering documentation should clearly separate runtime memory from parameter learning and avoid conflating the two.
3. Why the Database Keeps Growing
If a system keeps appending messages and tool results with no deletion, archival, or compression mechanism, data volume can grow continuously with usage over time.
A simplified estimate helps:
Daily data growth ≈ tasks per day × average events per task × average storage size per event
Here an “event” includes not only the dialogue between user and agent, but also tool calls, return values, failed retries, and execution state changes.
In real systems, tool results often take up more space than natural-language conversation. A single document read may produce long text, and a single data query may return a large number of records. If every execution round stores the complete result and keeps duplicates in several places, growth becomes even more pronounced.
Note that a database does not inevitably “grow forever.” Whether it keeps expanding depends on retention policy, storage format, deduplication, and how the database is maintained. Deleting logical records also does not immediately shrink the physical file; space reclamation still depends on the underlying storage mechanism.
Governance strategies include:
- Set retention periods by data category. Short-lived debugging logs, task audit records, and long-term user preferences should not share one lifecycle.
- Separate large payloads from retrieval metadata. Keep summaries, locations, and checksums in the database, and read the full body on demand.
- Eliminate duplicate content. Build content verification for identical documents or tool outputs to reduce repeated storage.
- Define archival and cleanup processes. Keep key conclusions and evidence, and delete expired temporary data according to policy.
- Control backup growth. Primary data, backup copies, and derived indexes should all be part of capacity planning.
These measures address storage cost, but storage optimization still cannot replace memory design.
4. Long-Term Memory Should Be Layered, Not Piled into One History Dump
A practical memory system can be organized into four categories by purpose.
1. Working memory: serving the current execution
Working memory holds the current task goal, completed steps, pending items, and temporary results. It changes frequently and usually only needs to cover one task or a limited session window.
For example, an agent assembling a data report needs to remember which files have been read and which fields have been checked, rather than rereading the entire process log every round.
2. Episodic memory: keeping traceable history
Episodic memory records “what happened when,” which suits task history, key decisions, and result evidence.
It should not enter the context in full every time. Instead, it should be retrieved when the user asks about past events, when the system needs to review what happened, or when the current task depends on the outcome of an earlier execution.
3. Factual memory: maintaining relatively stable information
Factual memory can hold explicitly stated output preferences, project terminology, and confirmed constraints.
Such information needs a recorded source, confirmation status, applicable scope, and last-updated time. A requirement from one project should not silently become the default rule for all projects, and a one-off remark from a user does not necessarily represent a permanent preference.
4. Procedural memory: reusable operating experience
Procedural memory describes the steps, checkpoints, and failure conditions for handling a class of tasks.
It cannot simply be a verbatim copy of one successful run. A genuinely reusable procedure states its preconditions, its applicable scope, and the steps that must be reconfirmed, especially operations involving external writes, resource deletion, or permission changes.
The point of layering is that different kinds of information get different update, recall, and invalidation strategies, instead of treating all history the same way.
5. Why Extraction and Compression Make Agents “Forget”
An agent’s forgetting does not necessarily happen at the storage layer. Even when the original records still exist, information can be lost during extraction, summarization, or recall.
Common risks include:
- A summary keeps the overall conclusion but drops the exception conditions.
- An explicit user constraint is not recognized as information that should be retained long term.
- A temporary guess is written down as a confirmed fact.
- A new summary is generated from an older summary, so errors accumulate round after round.
- Retrieval finds a similar topic but misses the actually relevant historical record.
So compression should not aim only at “shorter text”; it should protect task semantics first.
For a task summary, at minimum you should preserve as much as possible of:
- The current goal and acceptance criteria;
- Confirmed facts and key constraints;
- Actions already completed and their results;
- Unresolved problems;
- Where the evidence for important conclusions lives;
- Operations that must not be repeated.
For instance, “configuration processing complete” is short but almost useless for later execution. “Test environment configuration modified, effect not yet verified; production unchanged” preserves both state and boundary.
Summaries should also be traceable back to the original evidence. The compressed text exists to improve reasoning efficiency; the original records exist for verification, and neither should substitute for the other.
For requirements that truly cannot be dropped, relying only on automatic model judgment is unwise. Provide an explicit memory confirmation mechanism so users can view, modify, or delete key memories.
6. Historical Recall Should Target Relevance, Not Volume
Putting large amounts of historical messages back into the context looks like a way to reduce forgetting, but it usually introduces new problems: higher cost, conflicting information, divided attention, and stale content influencing the current decision.
A more reliable recall process narrows the candidate set step by step:
Current task analysis → permission and scope filtering → candidate retrieval → relevance ranking → validity and conflict checks → context assembly
First determine what the current task actually needs: user preferences, project constraints, historical conclusions, or detailed evidence from a specific execution.
Then filter by user, project, task, and permission boundaries, and look up candidates using lexical matching, semantic similarity, or structured conditions. No single retrieval method guarantees complete recall, so effectiveness has to be validated against the actual data.
The selected content should still be checked: has it expired, does it conflict with newer information, is it merely a historical guess, and is there enough evidence behind it?
Memory entering the context should carry its source and status. User-confirmed information, agent inferences, and facts returned by tools should not be presented as one undifferentiated block. Historical content must not automatically acquire the standing of an execution instruction, otherwise a wrong record or malicious text could interfere with the current task.
7. Break Token Cost Down Along the Execution Chain
Agent cost cannot be understood simply as “number of user questions.” One task may involve multiple model calls: planning, retrieval, tool selection, result analysis, verification, and the final answer.
A general cost estimate is:
Task model cost = sum of input token costs across all calls + sum of output token costs
If the actual service has other billing items, they should be added separately; storage, retrieval, tool execution, and network resources may also create additional cost.
High consumption usually comes from a few amplification mechanisms:
Repeated history input. Carrying long history in every round means the same content is processed again and again.
Oversized tool results. Handing the complete query result to the model instead of filtering, paginating, or extracting the necessary fields first inflates the input.
Low-quality recall. Retrieving irrelevant material adds cost and may trigger further retrieval and explanation.
Missing stop conditions. The agent loops between failed retries, plan rewrites, and repeated verification, never reaching a terminal state.
Optimization should reduce useless work first rather than bluntly truncating the context. You can cap the number of calls per task, the number of tool retries, and the total budget; trim large results to what the task needs; stop once acceptance conditions are met; and escalate to a human or return an explicit blocking reason when there is no progress for several consecutive rounds.
8. Fixing Repeated Tool Calls Starts With Execution State, Not Memory Text
Repeated calls may happen because the model never saw the earlier result, or because a tool timed out, returned an ambiguous response, or the system did not persist execution state. Not every case should be blamed on the model “not being smart enough.”
For important actions, maintain state that is independent of the natural-language summary, such as pending, running, completed, failed, or result uncertain, along with a parameter digest and a reference to the result.
If an action with external side effects returns a timeout, the system should not immediately conclude that it “did not succeed.” It should first query the execution result or confirm the state through verifiable evidence, and only then decide whether to retry.
Operations that can be made idempotent should be designed so that resubmitting the same business action does not take effect twice. High-risk operations that cannot be made idempotent need stricter confirmation and retry rules.
This kind of state management is more reliable than writing “do not call this again” in a summary, because it moves the execution constraint into program control.
9. How to Tell Whether an Optimization Actually Worked
Without observability data, it is hard to tell whether the problem lies in memory extraction, retrieval, context assembly, or tool execution.
It helps to record the following against the same task identifier:
- Input and output tokens and latency for each call;
- Retrieved candidates, the content finally selected, and the reasons for filtering;
- Memory addition, modification, invalidation, and deletion events;
- Tool call parameters, state, and retry reasons;
- The source records and versions behind summaries;
- The reason the task ended and the user’s confirmation result.
When evaluating, look at task completion rate, number of user corrections, repeated call rate, average latency, and cost per successful task at the same time. If cost drops but a key constraint is missed, the optimization does not count as effective.
It also helps to maintain a fixed set of test tasks covering cross-session preferences, condition changes, historical conflicts, and tool timeouts. Run regression tests after each change to memory or compression strategy, so that an improvement for short conversations does not break long tasks.
10. From a Usable Prototype to a Reliable System
For developers, a practical order of work is:
First, add call logging and task correlation identifiers so you can see where cost and failures actually occur.
Second, separate raw events, task state, and long-term memory, and define the purpose of each.
Third, build a memory structure with source, permissions, validity, and confirmation status.
Fourth, set budgets and stop conditions for recall, context, and execution.
Fifth, use the fixed task set to verify memory correctness, execution reliability, and cost changes.
Interaction history may also contain personal information, internal documents, and access credentials. Systems should apply data minimization for what is necessary, access isolation, sensitive-information handling, and a deletion mechanism that actually works; when a user deletes data, the lifecycle of related indexes, caches, and backups also has to be considered.
What high token consumption really signals is that an agent cannot sustain long-term operation on “a model plus a history log.” A reliable system must be able to explain why it remembered a piece of information, why it recalled this content, why it called the tool again, and why it should stop now.
In the end, the core measure of an agent is not consumption volume, but whether it completes tasks continuously and accurately within controllable cost and clear boundaries.
