---
title: "AI agent memory and context management"
description: "Store LangGraph checkpoints and ADK session history in Aerospike with automatic TTL expiry, concurrent-write safety, and unbounded conversation history."
---

# AI agent memory and context management

> For the complete documentation index see: [llms.txt](https://aerospike.com/docs/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](https://github.com/aerospike/langgraph-aerospike) and [adk-aerospike](https://github.com/aerospike-community/adk-aerospike). You need familiarity with Aerospike [records](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#records), [namespaces](https://aerospike.com/docs/database/learn/architecture/data-storage/data-model#namespaces), and [time to live (TTL)](https://aerospike.com/docs/database/learn/policies#expiration-time-to-live). 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:

| Type | What it stores | Example in these tutorials |
| :-- | :-- | :-- |
| Working state | The graph or session snapshot after each step | LangGraph checkpoints, ADK session rows, and events |
| Conversation history | Ordered user and assistant turns | Checkpoint 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](https://github.com/aerospike/langgraph-aerospike)) can carry a per-write [TTL](https://aerospike.com/docs/database/learn/policies#expiration-time-to-live). Aerospike removes expired records without a scheduled cleanup job. See the [Tutorial: Expiring chat sessions with LangGraph](https://aerospike.com/docs/develop/langgraph-expiring-chat-sessions).
-   TTL extension on read: [`Policy.readTouchTtlPercent`](https://aerospike.com/docs/database/learn/policies#expiration-time-to-live) and [`default-read-touch-ttl-pct`](https://aerospike.com/docs/database/reference/config#namespace__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](https://aerospike.com/docs/database/reference/limitations#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.

[Configure checkpoint TTL](https://aerospike.com/docs/develop/langgraph-expiring-chat-sessions/)

### 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.

[Fork from a saved checkpoint](https://aerospike.com/docs/develop/langgraph-agent-path-correction/)

### 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.

[Run concurrent writers](https://aerospike.com/docs/develop/adk-atomic-session-append/)

### 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.

[Append and read long history](https://aerospike.com/docs/develop/adk-infinite-chat-history/)

## Related pages

-   [Expiration (time to live)](https://aerospike.com/docs/database/learn/policies#expiration-time-to-live)
-   [System limits and thresholds](https://aerospike.com/docs/database/reference/limitations#maximum-record-size)