feat(sqlserver): add SQLServerSaver LangGraph checkpoint saver#630
Open
DevNinja (0xDevNinja) wants to merge 1 commit into
Open
feat(sqlserver): add SQLServerSaver LangGraph checkpoint saver#630DevNinja (0xDevNinja) wants to merge 1 commit into
DevNinja (0xDevNinja) wants to merge 1 commit into
Conversation
Adds `SQLServerSaver`, an implementation of `langgraph.checkpoint.base.BaseCheckpointSaver` backed by a SQL Server / Azure SQL database. Modeled after `langgraph.checkpoint.sqlite.SqliteSaver` so semantics match the other first-party savers, but adapted for SQL Server: SQLAlchemy + pyodbc transport, `MERGE` for upsert, `IF NOT EXISTS` for insert-or-ignore on writes, `TOP N` for `LIMIT`, and `JSON_VALUE` for metadata filters. The saver supports the same connection-string conventions as `SQLServer_VectorStore`, including Entra ID authentication when the connection string carries no credentials. Adds `langgraph-checkpoint>=2.0,<4.0` as a project dependency and exports `SQLServerSaver` from `langchain_sqlserver`. Closes langchain-ai#15
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
SQLServerSaver, an implementation oflanggraph.checkpoint.base.BaseCheckpointSaverbacked by a SQL Server / Azure SQL database. This is the LangGraph-persistence integration tracked in #15.Modeled after
langgraph.checkpoint.sqlite.SqliteSaverso behavior is consistent with the other first-party savers, adapted for SQL Server:pyodbctransport (sync), same connection-string conventions asSQLServer_VectorStoreincluding Entra ID authentication.MERGE INTO ... WHEN MATCHED THEN UPDATE ... WHEN NOT MATCHED THEN INSERTfor theputupsert.IF NOT EXISTS (...) INSERTfor theput_writesinsert-or-ignore path used for non-WRITES_IDX_MAPchannels.TOP Ninstead ofLIMIT Nforlist(..., limit=...).JSON_VALUE(metadata, '$.key')for the metadatafilter=argument.threading.Lockguards every session so concurrent graph runs in the same process cannot interleave statements on the underlying engine — mirrorsSqliteSaver's safety semantics.Closes #15
Public API
Implements
get_tuple/list/put/put_writes/delete_thread, plus a lazysetup()for table creation. Tables (checkpoints,checkpoint_writes) are configurable viacheckpoints_table/writes_tableanddb_schema.Files
langchain_sqlserver/checkpoint.py— new module withSQLServerSaver.langchain_sqlserver/__init__.py— export the new class.pyproject.toml+uv.lock— addlanggraph-checkpoint>=2.0,<4.0to project dependencies.tests/unit_tests/test_checkpoint.py— 8 unit tests covering construction validation, qualified-name building (schema / no-schema / overrides), Entra-ID-vs-uid/pwd routing, the empty-input fast path onput_writes, and SQL-injection guard on the metadata filter. No live DB required.tests/unit_tests/test_imports.py— extend the__all__snapshot.tests/integration_tests/test_checkpoint.py— 6 integration tests covering:put+get_tupleround-trip, latest-checkpoint lookup, descendinglistwithlimit,before=slicing,put_writesretrievability throughget_tuple.pending_writes, and scopeddelete_thread. Uses the existingTEST_AZURESQLSERVER_TRUSTED_CONNECTION/TEST_PYODBC_CONNECTION_STRINGenv vars.Test plan
ruff check langchain_sqlserver tests— cleanmypy langchain_sqlserver tests— clean (14 source files)pytest tests/unit_tests/— 9 passed (8 new + import snapshot), 1 module skipped (pre-existing)pytest tests/integration_tests/test_checkpoint.pyagainst a live SQL Server / Azure SQL instance.Notes
SQLServer_VectorStoreso users get identical auth semantics across vector store, chat history, and checkpoint saver. A follow-up to factor these into a shared internal module is reasonable, but kept out of this PR so it stays additive.poetry.lockis intentionally left in tree as-is —uv.lockis the canonical lockfile updated for the new dependency; happy to refreshpoetry.lockif maintainers prefer.