Skip to content

Commit 9dce3c8

Browse files
feat: Integrate Valkey with LangGraph LLM Cache (#717)
Enables use of Valkey to cache LLM responses in LangGraph
1 parent b16c995 commit 9dce3c8

File tree

10 files changed

+2939
-9
lines changed

10 files changed

+2939
-9
lines changed
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
22
LangGraph Checkpoint AWS - A LangChain checkpointer implementation using
3-
Bedrock Session Management Service.
3+
Bedrock Session Management Service and Valkey.
44
"""
55

66
from importlib.metadata import version
@@ -12,38 +12,42 @@
1212
AgentCoreMemoryStore,
1313
)
1414

15-
# Conditional imports for checkpoint functionality
15+
# Conditional imports for Valkey functionality
1616
try:
17+
from langgraph_checkpoint_aws.cache import ValkeyCache
1718
from langgraph_checkpoint_aws.checkpoint import AsyncValkeySaver, ValkeySaver
1819

1920
valkey_available = True
2021
except ImportError:
2122
# If checkpoint dependencies are not available, create placeholder classes
2223
from typing import Any
2324

24-
def _missing_checkpoint_dependencies_error(*args: Any, **kwargs: Any) -> Any:
25+
def _missing_dependencies_error(*args: Any, **kwargs: Any) -> Any:
2526
raise ImportError(
26-
"Valkey checkpoint functionality requires optional dependencies. "
27+
"Valkey functionality requires optional dependencies. "
2728
"Install them with: pip install 'langgraph-checkpoint-aws[valkey]'"
2829
)
2930

3031
# Create placeholder classes that raise helpful errors
31-
AsyncValkeySaver: type[Any] = _missing_checkpoint_dependencies_error # type: ignore[assignment,no-redef]
32-
ValkeySaver: type[Any] = _missing_checkpoint_dependencies_error # type: ignore[assignment,no-redef]
32+
AsyncValkeySaver: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
33+
ValkeyCache: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
34+
ValkeySaver: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
3335
valkey_available = False
3436

3537
try:
3638
__version__ = version("langgraph-checkpoint-aws")
3739
except Exception:
3840
# Fallback version if package is not installed
39-
__version__ = "1.0.0a1"
41+
__version__ = "1.0.0"
4042
SDK_USER_AGENT = f"LangGraphCheckpointAWS#{__version__}"
4143

4244
# Expose the saver class at the package level
4345
__all__ = [
4446
"AgentCoreMemorySaver",
4547
"AgentCoreMemoryStore",
4648
"AsyncValkeySaver",
49+
"ValkeyCache",
4750
"ValkeySaver",
4851
"SDK_USER_AGENT",
52+
"valkey_available",
4953
]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Cache implementations for LangGraph checkpoint AWS."""
2+
3+
from typing import Any
4+
5+
# Store the import error for later use
6+
_import_error: ImportError | None = None
7+
8+
# Conditional imports for optional dependencies
9+
try:
10+
from langgraph_checkpoint_aws.cache.valkey import ValkeyCache
11+
12+
__all__ = ["ValkeyCache"]
13+
except ImportError as e:
14+
# Store the error for later use
15+
_import_error = e
16+
17+
# If dependencies are not available, provide helpful error message
18+
def _missing_dependencies_error(*args: Any, **kwargs: Any) -> Any:
19+
raise ImportError(
20+
"Valkey cache functionality requires optional dependencies. "
21+
"Install them with: pip install 'langgraph-checkpoint-aws[valkey]'"
22+
) from _import_error
23+
24+
# Create placeholder classes that raise helpful errors
25+
# Use type: ignore to suppress mypy errors for this intentional pattern
26+
ValkeyCache: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
27+
28+
__all__ = ["ValkeyCache"]
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Valkey cache implementation for LangGraph checkpoint AWS."""
2+
3+
from typing import Any
4+
5+
# Store the import error for later use
6+
_import_error: ImportError | None = None
7+
8+
# Conditional imports for optional dependencies
9+
try:
10+
from .cache import ValkeyCache
11+
12+
__all__ = ["ValkeyCache"]
13+
except ImportError as e:
14+
# Store the error for later use
15+
_import_error = e
16+
17+
# If dependencies are not available, provide helpful error message
18+
def _missing_dependencies_error(*args: Any, **kwargs: Any) -> Any:
19+
raise ImportError(
20+
"Valkey functionality requires optional dependencies. "
21+
"Install them with: pip install 'langgraph-checkpoint-aws[valkey]'"
22+
) from _import_error
23+
24+
# Create placeholder classes that raise helpful errors
25+
# Use type: ignore to suppress mypy errors for this intentional pattern
26+
ValkeyCache: type[Any] = _missing_dependencies_error # type: ignore[assignment,no-redef]
27+
28+
__all__ = ["ValkeyCache"]

0 commit comments

Comments
 (0)