State and Memory Control
Separate short-term state from long-term memory to prevent leakage and confusion.
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.
Judgment question
What stays in the session, and what gets promoted to system 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.
Academic References
- The Rise of Agentic AI: Architectures, Taxonomies, and Evaluation Metrics — Future Internet (MDPI)