feat(agent-memory): add create_checkpointer() factory with TTL support for LangGraph agents#221
feat(agent-memory): add create_checkpointer() factory with TTL support for LangGraph agents#221santosh-nallur wants to merge 21 commits into
Conversation
…gents Adds factory/langgraph_checkpoint.py providing create_checkpointer() which returns LangGraph's InMemorySaver. The factory subpackage is structured to support future framework adapters (store, crewai) without namespace conflicts with the langgraph package itself. Persistent checkpointing backed by the Agent Memory Service is not yet supported. AGENTMAAS-410
Covers return type, ImportError on missing langgraph, and three LangGraph integration tests verifying compile, state persistence, and thread isolation. AGENTMAAS-410
…uide Adds a LangGraph Checkpointer section distinguishing the framework adapter from the core service client. Notes that the current implementation uses InMemorySaver and does not support persistence yet. AGENTMAAS-410
…create_checkpointer State loss on process exit is a relevant operational signal, not a routine info event. Message now names the function and describes the exact limitation. AGENTMAAS-410
Adds TimedInMemorySaver extending InMemorySaver with a daemon background sweep thread that evicts inactive threads based on ttl_seconds. Updates create_checkpointer(ttl_seconds=...) factory to return TimedInMemorySaver when ttl_seconds is provided, or plain InMemorySaver otherwise. TimedInMemorySaver is a temporary home in the SDK factory subpackage. It will migrate to langgraph-checkpoint-sap-agent-memory in Phase 2 — no code change required for consumers of create_checkpointer(). AGENTMAAS-410
…er guide Adds Thread TTL section to the LangGraph Checkpointer documentation covering ttl_seconds usage, TimedInMemorySaver eviction semantics, and the @agent_config decorator pattern for centralised TTL configuration. AGENTMAAS-410
… signature Removes TimedInMemorySaver and its tests. ttl_seconds is retained as a factory parameter for interface stability — TTL will be enforced by HanaAgentMemorySaver when available. InMemorySaver logs a clear warning when ttl_seconds is set explaining the current limitation. AGENTMAAS-410
The centralised TTL configuration via @agent_config is not yet available. Removed from both the factory docstring and the user guide. AGENTMAAS-410
Restores TimedInMemorySaver — InMemorySaver with background daemon sweep for production-grade TTL-based thread eviction. create_checkpointer() returns TimedInMemorySaver when ttl_seconds is set, InMemorySaver otherwise. AGENTMAAS-410
Documents ttl_seconds parameter, TimedInMemorySaver eviction semantics, and the process-exit limitation. Removes the placeholder text that said TTL has no effect. AGENTMAAS-410
| `langgraph` must be installed. The SDK does not declare it as a dependency — | ||
| you control your own LangGraph version. | ||
|
|
||
| ```bash | ||
| pip install langgraph | ||
| ``` |
There was a problem hiding this comment.
langchain is an optional dependency that we are using for the Agent Gateway module. We could follow the same approach here, adding langgraph as an optional dependency and validating and handling it with a proper message if the developer try to use the checkpointer without installing the langgraph dependency. Similar to what we did here:
There was a problem hiding this comment.
Thanks. I had it before, but removed it. I had an in-correct impression pip install sap-cloud-sdk[langgraph] would always restrict them to langgraph version we specify under optional section. But looking at it again, seems not the case because of bounds we use and additionally the agent devs could still specify a specific version.
| @@ -0,0 +1,117 @@ | |||
| """Unit tests for the create_checkpointer() LangGraph factory.""" | |||
There was a problem hiding this comment.
Better to keep same structure as src
There was a problem hiding this comment.
Looking at the existing test layout across all modules (tests/agentgateway/unit/, tests/destination/unit/, etc.), the convention is a flat list of test files under unit/ regardless of whether the source has subpackages. For example agentgateway/converters.py lives in a subpackage but its test is tests/agentgateway/unit/test_converters.py — not tests/agentgateway/unit/converters/test_converters.py.
Following that pattern, test_langgraph_checkpointer.py and test_timed_memory.py are in the right place under tests/agent_memory/unit/.
Could you clarify if you meant something else, like a different naming or structure convention?
Co-authored-by: Nicole Gomes <47161082+NicoleMGomes@users.noreply.github.com>
…equisites Adds langgraph>=0.2.0 to [project.optional-dependencies] so consumers can install via pip install sap-cloud-sdk[langgraph]. Updates the user guide prerequisites section to document both installation paths. AGENTMAAS-410
LangGraph 1.0 introduced the stable public API and current import paths. Pre-1.0 versions are not supported. AGENTMAAS-410
Shows how to expose ttl_seconds via agent_config decorator with key config.checkpointer.ttl_seconds for low-code UI integration. AGENTMAAS-410
|
Thanks @NicoleMGomes , @cassiofariasmachado, I realised that the new TTL field for checkpointer could be a configuration via decorators. Rather than introducing a new checkpointer specific decorator, reused the existing agent_config instead. Added an example in the user-guide.md |
Description
Adds a
create_checkpointer()factory in theagent_memorymodule that returns a LangGraphBaseCheckpointSaverappropriate for the current environment. Enables LoB teams (e.g. IBD) to integrate LangGraph agent short-term memory without coupling their agent code to a specific checkpointer implementation.What ships in this PR:
src/sap_cloud_sdk/agent_memory/factory/langgraph_checkpoint.py—create_checkpointer()factory returningInMemorySaver(no TTL) orTimedInMemorySaver(with TTL)src/sap_cloud_sdk/agent_memory/factory/_timed_memory.py—TimedInMemorySaverextendingInMemorySaverwith a daemon background sweep thread for TTL-based thread evictionsrc/sap_cloud_sdk/agent_memory/factory/__init__.py— factory subpackagetests/agent_memory/unit/test_langgraph_checkpointer.py— factory unit teststests/agent_memory/unit/test_timed_memory.py—TimedInMemorySaverunit testssrc/sap_cloud_sdk/agent_memory/user-guide.md— LangGraph Checkpointer sectionusage:
TimedInMemorySaverdesign:_last_activedict updated input()/aput()ttl_secondsof inactivityttl_secondsparameter stable for Phase 2 whenHanaAgentMemorySavershipsType of Change
How to Test
Checklist
Breaking Changes
None. The
factorysubpackage is additive. No existing public API is changed.Additional Notes
TimedInMemorySaveris a temporary home in the SDK factory subpackage. It will migrate tolanggraph-checkpoint-sap-agent-memory(the separate checkpoint library in Phase 2 — no code change required for factory consumers.ttl_secondsparameter is accepted oncreate_checkpointer()regardless of which backend is active, ensuring interface stability for Phase 2.HanaAgentMemorySaverships) will detect the HANA binding at runtime and return it automatically