When Agent Memory Works—and When It Fails

    Agent memory is not “store everything.” This article explains what to persist, how to update it, and when to retrieve it, using a four-quadrant evaluation of in-task vs. cross-task and knowledge vs. execution, plus cost-aware comparisons of long context, retrieval, and structured state.

    Agents can use interaction history inside a single call, but by default they do not keep a continuously updated state across independent calls. Stuffing the full history into context preserves raw evidence, yet it is bounded by window size, latency, and reasoning cost. External memory must therefore answer three questions: what to save, how to update it, and when to retrieve it. Evaluations that only score long-dialogue Q&A easily confuse “remembering facts” with “making later actions better.” A more complete approach crosses time scope (in-task / cross-task) with content type (knowledge / execution) to form four scenarios, and measures whether gains come from retrieving facts, maintaining execution state, or reusing problem-solving experience.

    Why a single Q&A score is not enough

    Knowledge memory cares whether entities, constraints, and intermediate conclusions can be retrieved and corrected. Execution memory cares whether exact parameters, tool returns, unfinished subgoals, and failure reasons can still drive the next action. In-task memory emphasizes state consistency in one session; cross-task memory emphasizes whether experience transfers to new instances or environments. When these four needs are mixed into one score, you cannot tell whether failure is missed retrieval, compression distortion, or a state machine that was never written.

    Common engineering mistakes include replacing action logs with dialogue summaries, replacing structured state with vector search, and treating “remembering what was said” as “remembering what can still be done.” Summaries fit narrative but drop numbers, identifiers, and order dependencies. Vector search fits semantically similar knowledge but is unfriendly to exact match and temporal constraints. Evaluation interfaces should therefore cover both knowledge Q&A and sequential decision-making with tools.

    Designing the four evaluation quadrants

    In-task knowledge: facts that appeared in the same task are later asked via implicit reference or paraphrase, testing whether original evidence can still be located rather than merely repeating the last sentence.

    In-task execution: recoverable entity names become references; multi-action turns with order dependence are split, while the legal action space stays the same. The focus is whether the agent maintains completed subgoals, pending parameters, and the last tool result.

    Cross-task knowledge: shared specs, constraints, and common pitfalls across instances in the same domain, testing whether abstracted knowledge is reusable rather than polluting the current task with identifiers from the previous instance.

    Cross-task execution: after accumulating policies and failure modes in a source environment, freeze memory and move to a slightly different target environment, testing whether experience is transferable procedural knowledge or overfit trajectory fragments.

    Two experiments must be separated: continuous in-group writes measure online adaptation; freeze-then-transfer measures generalization. Doing only the former overestimates “more memory is always better”; doing only the latter underestimates online correction.

    Read/write interface and update timing

    For fair comparison, the memory module should expose a unified read/write contract rather than hiding policy in prompt engineering. Typical operations: write (raw turns, tool traces, structured state), update (merge, deduplicate, invalidate), retrieve (by query, task id, time window), compress (summarize, slot-fill, extract rules). Update timing should at least distinguish: write every turn, abstract at task end, and force-record on failure. Different timings imply different noise and latency and must be reported under the same protocol.

    Compression is the effectiveness watershed. Lossless evidence helps correction but cost grows linearly with turns; over-abstraction cuts tokens but may drop exact fields needed for execution. In practice, use different compression strength: knowledge can be compressed semantically; execution state should be structured, checkable, and replayable.

    Performance must be viewed with cost

    Put long-context baselines, simple retrieval, and complex memory systems in one framework and count reasoning tokens for the agent and the memory module, retrieval counts, and write volume. The core question is not whether complexity is fashionable, but whether unit cost buys reproducible success-rate gains. If a complex system only slightly improves knowledge Q&A, is flat on execution, and uses far more tokens, treat it as ineffective complexity.

    A no-external-memory model remains a necessary control: it gives the upper and lower bounds of “stuff everything into context.” When tasks are short and locally dependent, external memory can yield zero or negative return (retrieval noise, bad summaries). When tasks are long, cross-session, and strongly sequential, structured execution memory is usually more stable than pure retrieval.

    When it works and when it fails

    More likely to work when later decisions clearly depend on exact historical state; tool results cannot be reconstructed from the current observation; cross-task constraints and failure modes can be abstracted; and writes are verifiable (for example key-value state or checked facts).

    More likely to fail when history and current task ids collide without isolation; compression drops numbers and order; retrieval uses only semantic similarity and ignores time and task boundaries; one-off trajectories are transferred as general policy; or the memory module itself occupies so much context that reasoning space is squeezed.

    Failure is often not “not remembering” but “remembering wrong and retrieving it first.” Evaluations should report the rate at which erroneous memories are cited, not only final task score.

    Practical guidance

    First build explicit state for the execution path (goals, parameters, tool results, blocking reasons), then a citable evidence store for the knowledge path. Default retrieval with task isolation and time decay. Field-level checks before compression. Score the four quadrants separately, and report success rate, state-consistency rate, tokens, and retrieval cost together. Only when gains are stable on the target quadrant and cost is acceptable should that memory strategy go to production.

    Agent memory is not better when it is more complete. It is better when, for the right time scope and content type, the information later decisions actually need becomes retrievable, updatable, and verifiable state. Measuring adaptation and transfer separately under a unified interface is what answers when memory works and when it fails.