Agents fail at the seams: a session dies mid-task, context overflows, or "memory" quietly becomes an unbounded compliance liability. This playbook designs the memory and state architecture — session versus long-term, checkpointing, context-window budgets, and the managed-versus-self-managed store decision — before the first outage teaches it.
Tier: Advanced · Hands-on time: ~35 minutes
The posting bar for this area names "orchestration, tool calling, memory, planning" as a set, and the managed platforms have made memory a product surface — AgentCore documentation describes runtime session state with sessions up to eight hours and a Memory service for short- and long-term context. That productization is convenient and consequential: what the runtime remembers for you is also what you must govern, budget, and be able to delete.
Separate the four kinds of state. Conversation context (what the model sees this turn), session state (task progress within one job), long-term memory (facts persisted across sessions), and audit state (what happened, for accountability — append-only, never fed back to the model uncurated). Designs go wrong by collapsing these into one blob; name them separately and give each its own store, retention, and access rules.
Set the context-window budget like a capacity plan. Allocate tokens per turn: system prompt, tool schemas, retrieved context, conversation history, and headroom for the response. Decide the eviction strategy for history (sliding window, summarization checkpoints, or retrieval from session state) before overflow forces an accidental one.
Design checkpointing around failure, not the happy path. Where can the task die (model error, tool timeout, runtime restart, session cap), and from which checkpoint does it resume? Decide checkpoint granularity (per tool call is the usual answer), what a checkpoint contains, and the idempotency rule for replayed tool calls — a resumed agent that re-executes a non-idempotent write is an incident.
Interrogate the long-term memory design hardest. Anita is adding cross-session memory to orbit-docs-copilot:
Interrogate this memory design before my review does.
Design: orbit-docs-copilot remembers, per user: product areas they ask
about, their plan tier, and a rolling summary of unresolved issues.
Stored in Postgres keyed by user ID; injected into the system prompt
each session; no expiry defined yet.
Attack it on:
1. Scope creep — what will engineers be tempted to add to this store,
and what boundary rule prevents "remember everything"?
2. Poisoning/staleness — how does a wrong or outdated memory get
corrected, and what does a stale "unresolved issue" do to answers?
3. Compliance — retention period, deletion path when the user or tenant
leaves, and whether any memory field is personal data under
DPDP/GDPR (assume yes unless argued otherwise).
4. Injection — memory content is model input; how does a manipulated
memory field become a prompt-injection vector?
For each: severity and the design change that closes it.
Make the managed-vs-self-managed store decision explicitly. Managed memory (AgentCore Memory-class) buys integration and lifecycle plumbing at the cost of platform coupling and whatever retention/residency semantics the platform offers — which you must verify, not assume. Self-managed (Redis/Postgres, LangGraph checkpointers) buys control and portability at the cost of owning schema, scaling, and deletion mechanics. Client tenancy or residency constraints frequently decide this before preference does; record the decision with exit cost, mirroring pb-35.
Give every stored item a lifecycle. For each state kind: TTL, refresh rule, deletion trigger (user request, tenant offboarding, retention expiry), and the concrete path that executes deletion — including checkpoints and any memory copies inside a managed runtime.
Ship the state architecture sheet. One table (state kind × store × retention × deletion path × access), the context-budget allocation, the checkpoint/resume sequence diagram, and an ADR for the store decision. This artifact is what pb-49's data-flow work will consume.
Memory stores concentrate exactly the data MSAs restrict — design them inside the client boundary. Self-managed state on client-subscription Redis/Postgres with client-tenancy model endpoints (Bedrock or Azure OpenAI in their tenancy) is the standard restricted pattern; managed memory services are usable only where the client's cloud and the platform's residency semantics both clear the contract, verified in writing. Development and checkpoint testing run fully local with LangGraph checkpointers plus an Ollama-served model. Synthetic user profiles stand in for real ones in every test; real personal data never seeds a test memory store.
Four state kinds, four lifecycles — a context budget, a checkpoint you have killed and resumed, a deletion path you have executed, and a store decision with its exit cost written down.