LLMs are stateless by design, and early agent developers simply dumped conversation history into context windows, which degrades performance as context grows. Token costs balloon, latency spikes, and the model struggles to identify current facts when multiple versions exist in context. The solution is treating memory and state as deliberate architectural choices rather than afterthoughts.

State is a snapshot of everything an agent currently knows—current task progress, tool call results, and tracked variables—functioning like a whiteboard that gets constantly updated and typically disappears when sessions end. Memory is the mechanism that carries information across boundaries: between turns, sessions, or even separate agents. Working memory handles turn-to-turn continuity, while semantic and episodic memory span sessions.

The memory-state cycle operates as: agents read from memory to build initial state at task start, continuously update state during work, then write select pieces back to memory upon task completion. Broken state causes agents to lose track mid-task; broken memory prevents learning and personalization. The five patterns address both concerns: Patterns 1 and 2 manage state, Patterns 3 and 4 build the persistent memory layer, and Pattern 5 constrains both.

Pattern 1, the In-Context Working Buffer, serves as short-term execution memory holding the ephemeral state of the current session—active prompts, recent turns, and live tool outputs—flushed when the session ends.