AI agent memory context state

Context, Memory & State

Separate what the model sees now, what the application knows, and what should persist across runs.

DIFFICULTY
Intermediate
EST. TIME
55 min
UPDATED
2026-08-19
On this page
  1. 01Definition
  2. 02Why it matters
  3. 03Step by step
  4. 04Build it
  5. 05Failure modes
  6. 06Production notes
  7. 07Sources

Learning objectives

  • Distinguish prompt context, application state, and persistent memory
  • Choose what to store, retrieve, summarize, or forget
  • Protect memory from stale, poisoned, or cross-user information

Prerequisites

Structured outputs · Basic database concepts

Answer first

Canonical definition

Context is the information provided to a model for the current call, state is the authoritative application record of the task, and memory is selected information persisted for later retrieval.

Operating context

Why it matters

Treating the conversation transcript as the database makes state hard to validate, migrate, or recover.

Useful memory is selective and attributable; storing everything increases privacy, cost, and contamination risk.

Method

Step by step

  1. 01

    Choose the source of truth

    Keep task status, permissions, and business records in application state rather than relying on model recollection.

  2. 02

    Assemble context

    Retrieve only the instructions, recent events, records, and evidence needed for the next decision.

  3. 03

    Write memory deliberately

    Define which observations can persist, their owner, source, confidence, expiry, and deletion rule.

  4. 04

    Test contamination

    Check for cross-user leakage, stale preferences, malicious retrieved text, and summary drift.

Hands-on lab

Design a resumable task state

Model an agent job that can pause for approval and resume without replaying or trusting the full chat transcript.

Deliverable

A state schema, context builder, memory policy, expiry rules, and resume tests.

What breaks

Common failure modes

  • F1Using summaries as the only authoritative record
  • F2Persisting unverified model claims as user facts
  • F3Retrieving memory without tenant and permission filters

Beyond the demo

Production notes

  • Encrypt sensitive state, scope it to tenant and user, and define retention before launch.
  • Version summaries and keep provenance links to the underlying records they compress.

Further reading

Sources

  1. [1]Anthropic: Context windows
  2. [2]NIST AI Risk Management Framework

Related Tenten resources

From capstone to production

A working demo is the beginning of the engineering problem.

Tenten helps teams scope one agentic workflow, integrate real data and permissions, define evals and handoffs, and own the path through launch and on-call.