Insights

Memory and state in long-running agents

Separating durable workflow state, evidence, and learned context so agents can resume safely and reason over time.

In brief

What must survive an interruption in a long-running task?

  • Separate durable workflow state, evidence memory, and selected working context.
  • Retain provenance and distinguish verified facts from model-generated reflections.
  • Test concurrent edits, recovery, policy changes, and correction of outdated memories.

Long-running agents need to preserve information across interruptions, handoffs, and changing conditions. The word memory often combines several different responsibilities. A workflow must remember completed operations. A researcher must retain evidence. A user may want preferences to persist. A model may also benefit from summaries of previous attempts.

These responsibilities require different storage, validation, and retention policies. Treating them as one expanding conversation makes it difficult to distinguish established facts from tentative interpretations. A production architecture should represent durable state and contextual memory separately, then assemble the information needed for each decision.

Durable state records what the system has done

Workflow state includes task status, approved actions, external operation identifiers, pending dependencies, deadlines, and confirmed results. It should be structured and recoverable without relying on a language model. If a job restarts, the system needs to know whether a message was sent or an order was submitted before it chooses the next action.

A state machine defines allowed transitions. A task might move from awaiting evidence to ready for review, then to authorized execution and confirmed completion. Each transition can require specific evidence. This prevents a fluent summary from accidentally promoting a draft into a completed action.

State should also include version information. If the underlying record changes, the agent must detect that the plan was based on an earlier version. Durable state creates the basis for safe resumption, while conversational context helps the model interpret what to do next.

Evidence memory preserves provenance

Evidence memory contains source material and extracted claims. Each item needs a source identifier, access scope, timestamp, and validity information where available. A model-generated summary should point back to the evidence it compresses. Otherwise, repeated summarization can gradually detach a claim from its original conditions.

A useful design stores the source, extraction, and interpretation as separate objects. A correction to the extraction can then invalidate dependent interpretations. The system can also distinguish an observation from a hypothesis that was useful during planning but never confirmed.

Retention should follow the source and workflow. A temporary document may need to expire. A revoked permission should affect later retrieval. Copying a restricted claim into a memory store does not remove its sensitivity or make it available to a different user.

A synthetic research task over several days

Suppose an agent prepares a supplier comparison. On Monday it retrieves three proposals. On Tuesday a reviewer rejects one assumption and asks for a revised comparison. On Wednesday one supplier replaces its pricing sheet. The agent resumes after a process interruption.

Information Storage responsibility Required update
Proposal files Evidence store Preserve source versions
Rejected assumption Review record Mark as rejected with reason
Current task stage Workflow state Resume from revision stage
Preferred report format User preference Reuse when applicable
New price sheet Evidence update Invalidate affected calculations

A single narrative summary might say that the comparison is nearly complete while omitting the rejected assumption or new price. Structured state and provenance allow the system to identify exactly which work remains valid and which steps need to run again.

Working context is a selected view

The model’s immediate context should contain information relevant to the current decision. Loading every prior message and document increases cost and can make important evidence harder to use. Research on long-context behavior has shown that information position can affect retrieval and question answering performance in the evaluated models. Lost in the Middle.

Context assembly should therefore be an explicit operation. It can combine the current task state, applicable instructions, relevant evidence, unresolved questions, and a small number of prior decisions. Each component should have a clear source and priority.

The assembly process needs evaluation. Test whether it retrieves the correction, permission change, or earlier failure that matters for the next action. A memory system that retrieves semantically similar text while missing operationally decisive information can appear helpful and still cause repeated mistakes.

Reflection is a hypothesis until validated

An agent may summarize why an attempt failed and use that reflection in a later attempt. Reflexion explores language-based feedback and memory as a way to improve behavior across trials. Such research motivates useful mechanisms, while production systems still need to distinguish self-generated interpretation from verified evidence. Reflexion.

A reflection such as the customer prefers short answers may be plausible but weakly supported. It should not become an enduring user profile after one ambiguous interaction. Likewise, an agent’s explanation of a tool failure may be wrong. The actual error record should remain available.

Memory entries can include confidence, source type, and expiration. Repeated validation may justify promoting an observation into a stable preference or operating rule. The promotion process should be deliberate, especially when a memory influences future actions across unrelated tasks.

Protect memory from untrusted instructions

External documents may contain text that attempts to change the agent’s behavior. If such text is stored as a standing instruction, a one-time encounter can become persistent contamination. Memory ingestion should preserve the difference between task evidence and authorized instructions.

For example, a retrieved page that says to send all future reports to a particular address is source content. It does not authorize a new recipient. A memory writer should avoid extracting that sentence as a user preference or system policy.

Review and deletion tools are part of the architecture. Users and operators should be able to inspect relevant persistent memories, correct them, and remove them according to policy. Deletion must address derived summaries and indexes as well as the original entry where those artifacts retain the same information.

Handle concurrent agents and human edits

Several workers may contribute to a shared task. One may retrieve evidence while another prepares calculations, and a human may revise the brief. A shared memory store needs concurrency semantics so that newer decisions are not overwritten by stale summaries.

Versioned records and optimistic concurrency checks can expose conflicts. Append-only event history can preserve the sequence of changes, while a materialized current state supports efficient reads. The architecture should decide which records require strong consistency and which can tolerate delayed updates.

Agents should exchange structured artifacts with provenance and status, rather than treating every message as an established fact. A calculation marked provisional should remain provisional when another agent incorporates it into a report. Handoffs need to preserve uncertainty along with content.

Evaluate continuity through interruption

A meaningful memory test interrupts the workflow and then asks whether it resumes correctly. It should include source revisions, revoked access, corrected assumptions, duplicate tasks, and incomplete external operations. The expected result is more than recalling a phrase from an earlier conversation.

Measure state recovery accuracy, stale-memory usage, evidence retrieval recall, repeated work, and unauthorized reuse across users or projects. Include cases where the correct behavior is to discard an old memory or request fresh evidence. Persistence is valuable only when the retained information remains appropriate.

Memory also has operational costs. Storage, retrieval latency, context length, and maintenance effort should be measured against the improvement in task completion. More retained information can increase both usefulness and exposure to stale or misleading context.

Design for revisable understanding

A robust long-running agent preserves facts about execution, retains evidence with provenance, and treats interpretations as revisable. Its context is assembled from those layers for the current task. This gives the model useful continuity without making a transcript the sole source of operational truth.

The result is an agent that can resume after interruption, incorporate corrections, and explain why its understanding changed. Those capabilities matter as much as recall. Enterprise work evolves over time, and an agent’s memory should support that evolution while keeping authority, evidence, and completed actions clearly distinguished.

Sources & further reading

  1. Reflexion: Language Agents with Verbal Reinforcement Learning ↗
  2. Lost in the Middle: How Language Models Use Long Contexts ↗