Spec: LangGraph Persistence Backends (Redis, Postgres, MongoDB)
Overviewβ
Enable pluggable persistence for both the LangGraph checkpointer (in-thread conversation state) and cross-thread memory store supporting Redis Stack, PostgreSQL, and MongoDB backends β all with graceful fallback to in-memory defaults.
Motivationβ
Currently, both persistence layers default to in-memory backends:
- Checkpointer (
InMemorySaver): Conversation state is lost on pod restart, causing multi-turn conversations to break. - Store (
InMemoryStorestub): Cross-thread memory is never persisted to Redis despiteLANGGRAPH_STORE_TYPE=redisbeing configurable.
Deploying a persistent backend (Redis Stack, PostgreSQL, or MongoDB) resolves both issues, enabling durable conversation state and true cross-thread memory persistence.
Scopeβ
In Scopeβ
- Add
langgraph-checkpoint-redis,langgraph-checkpoint-postgres,langgraph-checkpoint-mongodb, andmotorPython dependencies - Implement checkpointer factory (
checkpointer.py) withInMemorySaver/RedisSaver/PostgresSaver/MongoDBSaverbackends - Replace Redis store stub with real
AsyncRedisStorevia lazy wrapper - Add Postgres store via
AsyncPostgresStorelazy wrapper - Add MongoDB store via
motor-based_LazyAsyncMongoDBStorecustom wrapper - Wire both into supervisor (
deep_agent.py) and sub-agents (base_langgraph_agent.py) - Create
langgraph-redisHelm subchart with Redis Stack image - Add
checkpointPersistenceHelm values with redis/postgres/mongodb support and env var injection to supervisor-agent and agent templates - Add
memoryPersistencemongodb option to Helm values and templates - Unit tests for factory and store (65 tests)
- Spec and ADR documentation
Out of Scopeβ
- Data migration between backends
- UI changes
- Authentication/TLS for backends (handled at deployment level)
Designβ
Architectureβ
βββββββββββββββββββ ββββββββββββββββββββββββββββββββ
β supervisor-agentββββββΆβ Backend (configurable) β
β (deep_agent.py) β β ββββββββββββββββββββββββββ β
β β β β Checkpointer β β
β create_ β β β (Redis/Postgres/MongoDB)β β
β checkpointer() β β ββββββββββββββββββββββββββ€ β
β create_store() β β β Store β β
β β β β (Redis/Postgres/MongoDB)β β
βββββββββββββββββββ β ββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββ
βββββββββββββββββββ β
β sub-agents ββββββββββββββββββ
β (base_langgraph β
β _agent.py) β
β get_ β
β checkpointer() β
βββββββββββββββββββ
Checkpointer Backendsβ
| Backend | Package | Class | Env Var |
|---|---|---|---|
| Memory (default) | langgraph | InMemorySaver | LANGGRAPH_CHECKPOINT_TYPE=memory |
| Redis Stack | langgraph-checkpoint-redis | RedisSaver | LANGGRAPH_CHECKPOINT_TYPE=redis |
| PostgreSQL | langgraph-checkpoint-postgres | PostgresSaver | LANGGRAPH_CHECKPOINT_TYPE=postgres |
| MongoDB | langgraph-checkpoint-mongodb | MongoDBSaver | LANGGRAPH_CHECKPOINT_TYPE=mongodb |
Store Backendsβ
| Backend | Package | Class | Env Var |
|---|---|---|---|
| Memory (default) | langgraph | InMemoryStore | LANGGRAPH_STORE_TYPE=memory |
| Redis Stack | langgraph-checkpoint-redis | AsyncRedisStore (lazy) | LANGGRAPH_STORE_TYPE=redis |
| PostgreSQL | langgraph-checkpoint-postgres | AsyncPostgresStore (lazy) | LANGGRAPH_STORE_TYPE=postgres |
| MongoDB | motor | _LazyAsyncMongoDBStore (custom) | LANGGRAPH_STORE_TYPE=mongodb |
Components Affectedβ
- Multi-Agents (
ai_platform_engineering/multi_agents/) - Utils (
ai_platform_engineering/utils/) - Helm Charts (
charts/) - Documentation (
docs/)
Acceptance Criteriaβ
-
create_checkpointer()returnsRedisSaver,PostgresSaver, orMongoDBSaverwhen configured;InMemorySaverotherwise -
_create_redis_store()returns_LazyAsyncRedisStorewhenlanggraph-checkpoint-redisis installed -
_create_postgres_store()returns_LazyAsyncPostgresStorewhenlanggraph-checkpoint-postgresis installed -
_create_mongodb_store()returns_LazyAsyncMongoDBStorewhenmotoris installed -
deep_agent.pyusescreate_checkpointer()instead ofInMemorySaver() -
base_langgraph_agent.pyusesget_checkpointer()instead ofMemorySaver() -
langgraph-redisHelm subchart deploys Redis 8.0 (redis:8.0-alpine) -
checkpointPersistencevalues support redis, postgres, and mongodb in supervisor-agent and agent charts -
memoryPersistencevalues support redis, postgres, and mongodb - All 65 new unit tests pass
- Documentation (spec + ADR) created
Implementation Planβ
Phase 1: Dependenciesβ
- Add
langgraph-checkpoint-redis>=0.3.5,langgraph-checkpoint-postgres>=2.0.0,langgraph-checkpoint-mongodb>=0.3.0,motor>=3.4.0topyproject.toml
Phase 2: Checkpointer Factoryβ
- Create
ai_platform_engineering/utils/checkpointer.pywith memory/redis/postgres/mongodb backends
Phase 3: Store Backendsβ
- Replace
_create_redis_store()stub with_LazyAsyncRedisStore -
_LazyAsyncPostgresStore(already present from prior work) - Add
_create_mongodb_store()with_LazyAsyncMongoDBStorecustom wrapper
Phase 4: Wire into Agentsβ
- Update
deep_agent.pyandbase_langgraph_agent.py
Phase 5: Helm Subchartβ
- Create
charts/ai-platform-engineering/charts/langgraph-redis/
Phase 6: Helm Values & Templatesβ
- Add postgres/mongodb to
checkpointPersistencein supervisor-agent and agent charts - Add mongodb to
memoryPersistencein supervisor-agent chart - Inject
LANGGRAPH_CHECKPOINT_POSTGRES_DSN,LANGGRAPH_CHECKPOINT_MONGODB_URI,LANGGRAPH_STORE_MONGODB_URIenv vars in deployment templates
Phase 7: Testsβ
-
tests/test_checkpointer.py(29 tests β config, factory, singleton for all backends) -
tests/test_redis_store.py(36 tests β Redis, Postgres, MongoDB store wrappers + factory)
Phase 8: Documentationβ
- Spec and ADR
Testing Strategyβ
- Unit tests: Checkpointer factory (memory/redis/postgres/mongodb/fallback), Store wrappers (lazy init, delegation, sync rejection) for all three backends
- All 65 tests verified passing
- Manual verification: Deploy with
checkpointPersistence.type=redis|postgres|mongodbandmemoryPersistence.type=redis|postgres|mongodb
Rollout Planβ
- Merge PR and tag release
- Enable in preview: configure desired backend via
checkpointPersistence.typeandmemoryPersistence.type - For Redis: set
global.langgraphRedis.enabled=trueand point URLs atlanggraph-redisservice - For Postgres: provide DSN via
existingSecret(recommended) ordsn - For MongoDB: provide URI via
existingSecret(recommended) oruri - Verify conversation persistence across pod restarts
- Enable in production after validation
Relatedβ
- ADR: 2026-03-04-langgraph-redis-checkpoint-persistence
- ADR: 2026-02-26-cross-thread-langgraph-store
- PR: #861 (cross-thread memory store)