---
title: "State and Memory Control"
description: "Separate short-term state from long-term memory to prevent leakage and confusion."
canonical: "https://architecture.reopt.ai/patterns/state-and-memory-control"
language: "en"
last-updated: "2026-10-20"
alternate-markdown: "https://architecture.reopt.ai/ko/patterns/state-and-memory-control.md"
site-index: "https://architecture.reopt.ai/llms.txt"
source: "reopt architecture"
---

# State and Memory Control

> Separate short-term state from long-term memory to prevent leakage and confusion.

- **Category:** Collaboration & Coordination
- **OCLS phase:** LAYER
- **Slug:** `state-and-memory-control`

## Judgment question

What stays in the session, and what gets promoted to system memory?

## Context

Agents handle both session-scope state (current step, temporary variables) and long-term memory (learned patterns, user preferences, prior outcomes). Without separation, ephemeral state outlives the session or important memory is lost with it.

## Problem

With no boundary between state and memory, stale session state leaks into new sessions and triggers wrong decisions. The reverse failure — discarding learning at session end — causes the system to repeat the same mistakes. In multi-agent settings, conflicts over shared state must also be managed.

## Forces

- Remembering everything raises retrieval cost and noise; remembering selectively risks dropping critical signal.
- Centralized state gives consistency but becomes a bottleneck; distributed state introduces synchronization problems.
- Memory expiration is easy to manage but may discard memory that turns out to be needed longer than expected.

## Solution

Draw a hard line between session-scope short-term state and system-scope long-term memory. Short-term state is cleared automatically at session end; long-term promotion is governed by explicit criteria (repeated pattern, quality contribution, etc.). In multi-agent settings, define read/write permissions on shared memory per agent. Long-running agents need a compaction mechanism. The compaction pattern from Anthropic's [Effective Context Engineering for AI Agents] summarizes the conversation when the context window fills, initializing a new window while preserving architectural decisions, open bugs, and implementation details, and discarding duplicate tool output. The companion structured note-taking pattern — where the agent writes structured notes outside the context and reads them back — keeps state accurate across thousands of steps. A long context window (hundreds of thousands to a million tokens) being available does not mean every piece of information should be loaded into one window — "fit it all in a big window" versus "narrow it with context routing" is a trade-off across cost, latency, and attention budget, chosen per task. The intermediate reasoning trace of an extended-thinking model is session-scope short-term state, not long-term memory — never promote the thinking process itself to long-term memory.

## Application scenario

_Illustrative scenario — figures and company names in this page are hypothetical for explaining the pattern, not measured data._

Customer A asks about a shipping delay, then about changing payment method in the same session. Short-term state (current conversation, last response) is valid only inside the session. The fact that "this customer has experienced three consecutive shipping delays and previously received a 10% coupon" is promoted to long-term memory, managed by the Knowledge Agent. The Response Agent can read long-term memory but not write it; it can only request promotion. The QA Agent validates the promotion criteria (≥3 occurrences, quality contribution) before the write lands.

## How it breaks

Without separation, the previous session's shipping-delay context bleeds into the new session's payment-change response — an inappropriate "sorry your shipment is delayed" opens a reply about billing. The opposite failure — wiping everything at session end — leaves the system unable to consult prior resolutions when the same customer returns with the same problem, so it proposes the same answer again.

## Implementation pattern bridge

- Session Store / Vector Memory

Mostly an infrastructure-design concern. Key implementation work: separating session store (short term) from vector DB / knowledge base (long term) and controlling read/write authority.

## Related

- [Context Routing](https://architecture.reopt.ai/patterns/context-routing.md)
- [Evaluation and Guardrails](https://architecture.reopt.ai/patterns/evaluation-and-guardrails.md)

## References

- The Rise of Agentic AI: Architectures, Taxonomies, and Evaluation Metrics — Future Internet (MDPI)

---

_Markdown representation of https://architecture.reopt.ai/patterns/state-and-memory-control. Full index: https://architecture.reopt.ai/llms.txt HTML original: https://architecture.reopt.ai/patterns/state-and-memory-control · 한국어: https://architecture.reopt.ai/ko/patterns/state-and-memory-control.md_
