← Notes
blog · May 22, 2026

Agent Context Management and Engineering

A survey of context assembly, retrieval, persistent memory, and information flow in LLM agents.

Agent

A conversational assistant needs to distinguish a user’s current preference from an older one. A coding agent needs the relevant files and test results without carrying every terminal output into each call. A research assistant needs to connect evidence gathered at different points in a task. These are different workloads, but each depends on how information becomes available to the model over time.

The work relevant to these problems spans long-context modeling, retrieval, prompt compression, agent memory, and orchestration. The terminology overlaps, and the evaluations often ask different questions. A method that improves document retrieval may say little about whether an assistant handles a changed preference or whether an agent completes a sequence of actions.

This survey organizes selected work around those differences: assembling context for one model call, retaining memory across interactions, and moving information through an agent system. The final sections compare evaluation settings and the questions they leave open.

Context, state, and memory

Here, context means the information supplied to a particular model call: instructions, conversation, retrieved material, tool definitions, and observations. State is the application’s record of the ongoing task, including completed actions and intermediate results. Memory is retained information that can be brought back into use after it has left the active context, within a task or across sessions.

These are working definitions rather than a universal taxonomy. They separate what the system holds from what the model currently sees. Saving a conversation gives the application a record; a later call still needs a way to locate and interpret the relevant parts.

Context engineering covers the decisions that connect these layers. Prompt wording is one part of it. Selection, ordering, retrieval, summarization, memory updates, and the timing of reads and writes also determine the input to a model call. Some decisions can be fixed application rules; others can be delegated to a model or learned policy.

It also helps to distinguish memory’s lifetime from its representation. An event log, an extracted fact, and an executable skill can all persist across sessions. They preserve different things, however, and support different kinds of retrieval. Calling all three “long-term memory” hides much of the design choice.

Assembling context for one model call

Longer windows and evidence selection

A larger context window allows more source material to remain visible. That can reduce dependence on an early retrieval or summarization step, especially when a question requires connecting evidence across a document. It also moves more of the selection burden into the model: the input may contain the answer alongside many irrelevant passages.

Lost in the Middle examined multi-document question answering and key-value retrieval. In its experiments, performance varied with the position of the relevant information, often deteriorating when that information appeared in the middle. The finding concerns the models and tasks evaluated; it does not establish a fixed limit for every later long-context model. It does establish why nominal window size and effective use of evidence need separate measurement.

For a given workload, full-context input is therefore a useful comparison point. A retrieval system can fail by excluding evidence before generation begins. A full-context system can receive the evidence and still fail to use it. Looking only at the final answer makes these failures difficult to distinguish.

Retrieval: what to fetch, and when

Retrieval narrows the material available to the model. Its effectiveness depends on the unit being indexed, the query, and whether the question can be answered from a few independently relevant passages.

HippoRAG addresses associative retrieval using an LLM-derived knowledge graph and Personalized PageRank, evaluated on multi-hop question answering. Its relevance here is the retrieval structure: relationships can help connect evidence that passage similarity alone might not bring together. Graph construction also introduces another place where extraction errors or missing links can affect the result. Graph-based retrieval is a candidate for relational questions, with costs that need comparison against simpler retrieval on the same workload.

A separate choice is when to retrieve. Self-RAG trains a model to retrieve on demand and use reflection tokens to assess retrieved passages and generated text. This makes retrieval part of generation behavior rather than a mandatory prefix to every request. The distinction matters when the need for evidence becomes clear only after an intermediate reasoning step.

These approaches address different dimensions. A system can use a graph index with a fixed retrieval schedule, or a passage index with adaptive retrieval. Comparing them requires stating which part changed; “better RAG” is too broad to explain the result.

Compression and summarization

Selection removes material from consideration. Compression reduces the representation of material that has already been selected. LLMLingua combines budget control and token-level compression to shorten prompts. A natural-language summary makes a different transformation: it rewrites the input into a new account of its contents.

Both can lower the volume carried into later calls, but the information loss differs. A summary may retain the main conclusion while dropping qualifications or the sequence of events. Token-level compression may preserve more of the original wording while making it harder to inspect as ordinary prose. Neither should be evaluated on compression ratio alone.

The appropriate test depends on what the retained material must support. Document question answering, following a changing plan, and recalling a user’s earlier correction can require different details. Compression that works for the current query may be poorly suited to an unknown follow-up. That uncertainty connects context reduction to the design of persistent memory.

Retaining memory across interactions

Events, facts, and skills

An event records what happened in a particular situation. An extracted fact offers a compact statement that may be useful elsewhere. A skill represents a reusable procedure. Moving from an event to a fact or skill introduces interpretation: the system decides which details to retain and which parts generalize.

Generative Agents combines records of experience with retrieval, higher-level reflection, and planning in a simulated social environment. Reflections offer abstractions over observations, while the underlying experiences provide a more specific record. The paper’s evaluation concerns believable behavior in that environment, so its results should be read within that setting.

Voyager stores executable code skills that an agent accumulates and retrieves in Minecraft. This lets the agent reuse behavior. Its setting makes execution feedback available, which is useful for evaluating a stored procedure in a way that a conversational memory system may not be able to do.

The comparison shows why memory representation should follow its intended use. A preference can be stored as a fact with its source and time. Reconstructing a disputed interaction may require the original exchange. Repeating a successful action may benefit from a procedure, together with the conditions under which it worked.

Organization and memory control

MemGPT treats context management as movement between memory tiers, drawing on the analogy of operating-system memory. Its experiments include document analysis and multi-session conversation. The architectural idea is to make access to information outside the active window an explicit part of the agent’s control flow.

A-Mem focuses on how stored memories are organized. It generates notes with attributes such as descriptions, keywords, and tags, links related notes, and updates contextual representations as new memories arrive. This differs from treating memory as a collection of independently embedded chunks: a write can change the organization of existing material.

AgeMem, a 2026 preprint in the version considered here, makes memory operations part of a learned agent policy. Storing, retrieving, updating, summarizing, and discarding information become actions trained with reinforcement learning. It offers an alternative to hand-written rules, while introducing dependence on the tasks and rewards used during training.

Together, these works separate two questions that are often bundled: how memory is represented, and who controls its use. Linked notes do not require a learned controller; a learned controller need not use a graph. Keeping those axes separate makes comparisons easier to interpret.

Updates, provenance, and forgetting

Persistence also creates a consistency problem. A later statement might correct an earlier one, apply only temporarily, or describe another person’s preference. Appending both statements preserves history, but does not tell the reader which is currently applicable. Replacing the earlier statement simplifies retrieval, but can remove the evidence needed to explain a change.

A useful design distinction is between retaining an event and treating it as a current fact. Timestamps, sources, and links between corrections can support that distinction. Forgetting likewise has several meanings: removing an item from the active context, lowering its retrieval priority, or deleting the stored record. Those operations have different consequences and should be described separately in an evaluation.

Information flow through an agent system

A memory mechanism sits inside a larger execution loop. Observations arrive, state changes, context is assembled, and the model produces an answer or another action. The following diagram is a conceptual decomposition, rather than the architecture of a particular paper.

flowchart TD
    E["Messages and observations"] --> S["Task state"]
    S --> C["Context assembly"]
    M[("Persistent memory")] --> C
    C --> L["Model call"]
    L --> O["Answer, tool call, or agent message"]
    O --> E
    S --> W["Memory write or update"]
    W --> M

Tools and long-running tasks

Tool use adds both information and state changes to this loop. Tool descriptions compete for context space; results can be long; later actions can depend on earlier outputs. LongFuncEval studies these pressures through large tool catalogs, long tool responses, and long multi-turn conversations. Its setup connects long-context evaluation to function calling.

The resulting design choices include which tool definitions to expose, which observations to carry forward, and when an older result needs to be refreshed. These choices interact with task state. A summary of an action and a record that the action actually completed are different inputs to the next decision. Evaluating only the readability of the summary would miss that distinction.

Multiple agents and shared context

With multiple agents, context is distributed across participants. AutoGen is an early framework example built around configurable conversations among agents, tools, and humans. The communication pattern determines which intermediate results reach each participant.

A shared conversation gives agents access to the same discussion, at the cost of repeatedly exposing them to material intended for other roles. Separate contexts can support specialization, but make handoffs depend on what the sender chooses to communicate. Shared memory adds another option: agents can retrieve from a common store while keeping their immediate working contexts distinct.

This creates questions about ownership and interpretation. Who can revise a shared fact? Can a receiving agent inspect the evidence behind another agent’s conclusion? Does a message report an observation, a hypothesis, or a completed action? These are design questions arising from distributed context; adding more participants does not answer them automatically.

What the evaluations measure

The benchmarks below examine different parts of context and memory handling. Their scores are useful within their task definitions, but do not form a single ranking of agent memory quality.

EvaluationMain focusWhat it leaves to other tests
Lost in the MiddleUsing evidence at different input positionsMemory updates and interactive actions
LoCoMoLong-term conversations, including QA and summarizationGeneral tool execution
LongMemEvalExtraction, cross-session and temporal reasoning, updates, abstentionEnd-to-end action completion
LongFuncEvalFunction calling under long-context conditionsBroader memory lifecycles
ToolSandboxStateful tool interaction and execution milestonesGeneral long-term conversational recall

LoCoMo uses long conversations generated with an agent-based pipeline and checked by human annotators. LongMemEval separates memory abilities that can disappear inside an aggregate QA score, particularly knowledge updates and abstention. Both make sustained conversational history part of the evaluation, though their construction and questions differ.

ToolSandbox adds stateful execution and intermediate as well as final milestones. That makes it possible to inspect whether an agent reached the required state through its actions. It answers a different question from whether a model can retrieve a fact from a supplied history.

For comparing context policies, the most informative analysis separates evidence availability, evidence use, and task outcome. Was the required information stored? Did retrieval select it? Did assembly preserve enough context to interpret it? Did the model use it correctly? A failure can occur at any of these stages, and the remedy depends on which stage failed.

Operational measurements belong alongside accuracy: total tokens, retrieval and write costs, end-to-end latency, and storage growth. A shorter prompt may require additional retrieval calls. An elaborate memory-writing process may improve later answers while making the current interaction slower. The comparison needs to account for that work across the relevant task or session.

Open questions

One unresolved choice is how much a system should decide at write time. Extracting compact facts makes later reads simpler, but commits early to an interpretation of what matters. Keeping richer episodes leaves more options for future questions, while increasing the burden on retrieval and reading. A useful comparison would vary the future questions, especially those that need details omitted by the original extraction.

Memory revision raises a related problem. Updating one summary does not necessarily update all the notes, links, or derived facts that depend on it. Evaluations could make those dependencies explicit: introduce a correction, then ask questions whose answers should change and others whose answers should remain stable. This would test the consequences of an update beyond finding the newest statement.

Learned memory control also needs evidence about transfer. A policy trained to manage context for one task distribution may retain the wrong information when tools, users, or task horizons change. The question is where its gains survive those changes, compared with simpler rules under the same resource budget.

I find the separation between representation, control, and evaluation the most useful way to read this literature. It makes the assumptions visible: what information a method stores, how it becomes available again, and what evidence shows that it helped. That provides a basis for choosing methods for a workload, while leaving room for different answers in conversation, document analysis, coding, and collaborative agents.

References