Skip to content

Commit 155c1a3

Browse files
feat(langgraph-checkpoint-aws): add Valkey checkpoint saver for AgentCore (#738)
This PR provides AgentCore-compatible checkpoint savers that use Valkey as the storage backend, combining AgentCore session management concepts with Valkey's storage and search capabilities.
1 parent b550f0d commit 155c1a3

File tree

15 files changed

+4712
-31
lines changed

15 files changed

+4712
-31
lines changed

libs/langgraph-checkpoint-aws/README.md

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ pip install 'langgraph-checkpoint-aws[valkey]'
3838
This package provides following main components:
3939

4040
1. **AgentCoreMemorySaver** - AWS Bedrock-based checkpoint storage
41-
2. **AgentCoreMemoryStore** - AWS Bedrock-based document store
42-
3. **ValkeyCache** - Valkey LLM response cache
41+
2. **AgentCoreValkeySaver** - AgentCore-compatible Valkey checkpoint storage
42+
3. **DynamoDBSaver** - DynamoDB-based checkpoint storage with S3 offloading
4343
4. **ValkeySaver** - Valkey checkpoint storage
44-
5. **ValkeyStore** - Valkey document store
45-
6. **DynamoDBSaver** - DynamoDB-based checkpoint storage with S3 offloading
46-
44+
5. **AgentCoreMemoryStore** - AWS Bedrock-based document store
45+
6. **ValkeyStore** - Valkey document store
46+
7. **ValkeyCache** - Valkey LLM response cache
4747

4848
## Usage
4949

@@ -248,7 +248,47 @@ with ValkeySaver.from_conn_string(
248248
result = graph.invoke(1, config)
249249
```
250250

251-
### 6. Valkey Store for Document Storage
251+
### 6. AgentCore Valkey Storage
252+
253+
For AWS Bedrock AgentCore-compatible applications that want to use Valkey instead of managed Memory:
254+
255+
```python
256+
from langgraph.prebuilt import create_react_agent
257+
from langgraph_checkpoint_aws import AgentCoreValkeySaver
258+
259+
# Using connection string
260+
with AgentCoreValkeySaver.from_conn_string(
261+
"valkey://localhost:6379",
262+
ttl_seconds=3600, # 1 hour TTL
263+
pool_size=10
264+
) as checkpointer:
265+
# Create your agent
266+
graph = create_react_agent(
267+
model=model,
268+
tools=tools,
269+
checkpointer=checkpointer
270+
)
271+
272+
# AgentCore-style configuration (requires actor_id)
273+
config = {
274+
"configurable": {
275+
"thread_id": "session-123",
276+
"actor_id": "agent-456", # Required for AgentCore compatibility
277+
"checkpoint_ns": "production"
278+
}
279+
}
280+
281+
result = graph.invoke({"messages": [...]}, config)
282+
```
283+
284+
**Key Differences from ValkeySaver:**
285+
- ✅ Requires `actor_id` in configuration (AgentCore requirement)
286+
- ✅ Uses AgentCore-compatible key structure (`agentcore:*` prefix)
287+
- ✅ Built-in retry logic with exponential backoff
288+
- ✅ Pydantic validation for data integrity
289+
- ⚠️ **Data is NOT compatible with ValkeySaver** - choose one at project start
290+
291+
### 7. Valkey Store for Document Storage
252292

253293
Document storage with vector search capabilities using ValkeyIndexConfig:
254294

libs/langgraph-checkpoint-aws/langgraph_checkpoint_aws/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
from importlib.metadata import version
7+
from typing import Any
78

89
from langgraph_checkpoint_aws.agentcore.saver import (
910
AgentCoreMemorySaver,
@@ -14,6 +15,7 @@
1415

1516
# Conditional imports for Valkey functionality
1617
try:
18+
from langgraph_checkpoint_aws.agentcore import AgentCoreValkeySaver
1719
from langgraph_checkpoint_aws.cache import ValkeyCache
1820
from langgraph_checkpoint_aws.checkpoint import AsyncValkeySaver, ValkeySaver
1921
from langgraph_checkpoint_aws.store import (
@@ -42,17 +44,20 @@
4244
)
4345

4446
valkey_available = True
45-
except ImportError:
46-
# If dependencies are not available, create placeholder classes
47+
except ImportError as e:
48+
# Store the import error for better debugging
49+
_import_error = e
50+
4751
from typing import Any
4852

4953
def _missing_dependencies_error(*args: Any, **kwargs: Any) -> Any:
5054
raise ImportError(
5155
"Valkey functionality requires optional dependencies. "
5256
"Install them with: pip install 'langgraph-checkpoint-aws[valkey]'"
53-
)
57+
) from _import_error
5458

5559
# Create placeholder classes that raise helpful errors
60+
AgentCoreValkeySaver: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
5661
AsyncValkeySaver: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
5762
AsyncValkeyStore: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
5863
ValkeyCache: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
@@ -79,6 +84,7 @@ def _missing_dependencies_error(*args: Any, **kwargs: Any) -> Any:
7984
__all__ = [
8085
"AgentCoreMemorySaver",
8186
"AgentCoreMemoryStore",
87+
"AgentCoreValkeySaver",
8288
"AsyncValkeySaver",
8389
"AsyncValkeyStore",
8490
"ValkeyConnectionError",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,34 @@
1+
from typing import Any
2+
13
from langgraph_checkpoint_aws.agentcore.saver import AgentCoreMemorySaver
24
from langgraph_checkpoint_aws.agentcore.store import AgentCoreMemoryStore
35

6+
# Store the import error for later use
7+
_import_error: ImportError | None = None
8+
9+
# Conditional imports for optional dependencies
10+
try:
11+
from langgraph_checkpoint_aws.agentcore.valkey import AgentCoreValkeySaver
12+
13+
valkey_available = True
14+
except ImportError as e:
15+
# Store the error for later use
16+
_import_error = e
17+
valkey_available = False
18+
19+
# If dependencies are not available, provide helpful error message
20+
def _missing_valkey_dependencies_error(*args: Any, **kwargs: Any) -> Any:
21+
raise ImportError(
22+
"AgentCore Valkey functionality requires optional dependencies. "
23+
"Install them with: pip install 'langgraph-checkpoint-aws[valkey]'"
24+
) from _import_error
25+
26+
# Create placeholder class that raises helpful error
27+
AgentCoreValkeySaver: type[Any] = _missing_valkey_dependencies_error # type: ignore[assignment,no-redef]
28+
429
__all__ = [
530
"AgentCoreMemorySaver",
631
"AgentCoreMemoryStore",
32+
"AgentCoreValkeySaver",
33+
"valkey_available",
734
]

0 commit comments

Comments
 (0)