Skip to content

AI agent memory and context management

For the complete documentation index see: llms.txt

All documentation pages available in markdown.

This overview page explains how Aerospike Database stores memory and context for AI agents built with LangGraph or Google Agent Development Kit (ADK). It is for developers building stateful agents that must resume after restarts, share sessions across workers, or retain long conversation history.

It applies to Aerospike Database on all supported versions, plus the community packages langgraph-checkpoint-aerospike and adk-aerospike. You need familiarity with Aerospike records, namespaces, and time to live (TTL). After reading, you can choose the right Aerospike-backed memory pattern for LangGraph checkpoints or ADK sessions and follow the linked tutorial for each pattern.

Agent memory and context in Aerospike

Agent memory is the durable state an agent needs to act consistently across turns, restarts, and concurrent workers. It has two common forms:

TypeWhat it storesExample in these tutorials
Working stateThe graph or session snapshot after each stepLangGraph checkpoints, ADK session rows, and events
Conversation historyOrdered user and assistant turnsCheckpoint message history and ADK event streams

Agents rarely send full history to the model on every turn. Frameworks load recent turns for the context window, load full history for audit or export, or rewind to an earlier checkpoint to fork execution. Aerospike-backed integrations support these read patterns through direct key-based reads at the storage layer.

Why Aerospike for agent memory

These tutorials use Aerospike Database for agent memory because its features apply directly to agent lifecycles:

  • Automatic session expiry: LangGraph checkpoints stored with AerospikeSaver (the checkpoint backend from langgraph-checkpoint-aerospike) can carry a per-write TTL. Aerospike removes expired records without a scheduled cleanup job. See the Tutorial: Expiring chat sessions with LangGraph.
  • TTL extension on read: Policy.readTouchTtlPercent and default-read-touch-ttl-pct control whether reading a record extends its TTL. Set these values to match whether an active session should stay alive when the agent loads its state.
  • Safe concurrent writes: ADK sessions can receive parallel append_event calls from sub-agents or retried network writes. AerospikeSessionService uses atomic, idempotent appends so events and state stay consistent under load.
  • Unbounded history through sharding: A single Aerospike record has a maximum record size. AerospikeSessionService splits long ADK sessions into segment records and rolls over to a new segment when a page fills, so conversation history can grow without truncation.

Memory patterns

Expiring session checkpoints

LangGraph writes a checkpoint after every graph step. AerospikeSaver stores each checkpoint as an Aerospike record keyed by thread_id and checkpoint_id, and stamps TTL at write time.

Expiring chat sessions with LangGraph
Configure AerospikeSaver TTL so abandoned LangGraph checkpoints expire without a cleanup job.

Fork and resume from a checkpoint

When an agent path changes after expensive work, restarting wastes API calls and parsing time. LangGraph checkpoints let you list history, load the field values frozen at a past state back into the running graph (also known as rehydrating), and fork to a corrected path while keeping the original checkpoint for reference.

Agent path correction with LangGraph
Fork a LangGraph thread from a saved checkpoint and resume with corrected input.

Atomic concurrent session writes

Multi-agent ADK applications can append to the same session from parallel workers. If writes are not atomic or idempotent, retries and concurrent appends can duplicate turns or corrupt session state.

Atomic session append with ADK
Store ADK session events with safe concurrent appends and no duplicate writes.

Unbounded history with segment sharding

Long-running ADK conversations can reach thousands of turns. Storing every event in one record eventually hits Aerospike’s per-record size limit. Segment sharding spreads events across numbered segment records while preserving order and supporting partial reads.

Infinite chat history with ADK
Store long-running ADK conversations with segment sharding and context-window reads.