generated from langchain-ai/integration-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
INTPYTHON-377 langgraph-checkpoint-mongodb #7
Merged
caseyclements
merged 76 commits into
langchain-ai:main
from
caseyclements:INTPYTHON-377-LANGGRAPH-CHECKPOINTER
Nov 22, 2024
Merged
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
1b1130c
Added new package langgraph-checkpoint-mongodb
caseyclements fefa0e1
Copies from langgraph everything to run test_pregel
caseyclements 4aca7e5
Add snapshot files (run tests with --snapshot-update)
caseyclements 8373eda
Test cleanup. There are 5 of 123 failing
caseyclements b3277a7
Marked points of failure and added a couple notes
caseyclements 3ded014
Fixed test_pregel::test_root_graph. Related to deterministic_uuids fe…
caseyclements 0d38a26
Replace ALL_CHECKPOINTERS_SYNC in test_root_graph
caseyclements c2dc0ce
Fixed tests related to subgraphs and checkpoint_ns. One left that may…
caseyclements 9a815f2
linting
caseyclements 94bab6f
Added pytest-repeat
caseyclements 8794bd9
Turned async tests backed on
caseyclements a9a5a4b
Applied WRITES_IDX_MAP.get and checkpoint_ns fixes to AsyncMongoDBSaver
caseyclements d328a68
Updated poetry.lock after adding pytest-repeat
caseyclements 64fa394
Added snapshots for test_pregel_async
caseyclements 8daded4
Updated setup of _checkpointer_mongodb_aio
caseyclements fe6cd14
Added missing pending_writes in alist
caseyclements c0481e2
Addd TODO to test as it might be another red herring
caseyclements 730cae6
Following advice from Actions, updated libs in check_diff
caseyclements bdf4b2b
Adjusting pyproject.toml to see if we can use existing Github Actions
caseyclements 070ac48
Added empty test_integration group in pyproject for CI
caseyclements 313a5c2
Update content-hash of poetry.lock
caseyclements 2b1de87
formatting
caseyclements 960d773
Had forgotten to await checkpointer.clxn_chkpnt.delete_many
caseyclements 111b4c9
Add blocking methods to AsyncMongoDBSaver
caseyclements edd1969
Added compatability methods async and aiter for py3.9
caseyclements 0658d00
formatting
caseyclements f8f602f
Updated logic in check_diff to avoid linting langgraph-checkpoint-mon…
caseyclements 5ba00f3
Typo
caseyclements 2940c3c
Updated logic in check_diff to avoid linting langgraph-checkpoint-mon…
caseyclements eed64e9
Temporarily turn off make lint_test.
caseyclements 594642e
Set mongodb client hosts for CI
caseyclements 7285839
Added placeholder used for compiling integration tests without runnin…
caseyclements d6b85da
Added compile and requires to available pytest markers
caseyclements 9197152
Updated db_name to langgraph_checkpoints_db for clarity
caseyclements 706fbd9
Removed 3.9 from python version matrix to see id anext workaround was…
caseyclements f9b3142
Merge branch 'main' into INTPYTHON-377-LANGGRAPH-CHECKPOINTER
caseyclements a307500
Added supercharge github action to mongodb demon instead of a remote …
caseyclements b4c62d0
Revert "Removed 3.9 from python version matrix to see id anext workar…
caseyclements 71b90a9
Found hardcoded string
caseyclements 38e7ff8
Allow override of uri and db_name via environ for testing
caseyclements d940864
pytest skipped: test_prebuilt_tool_chat as a fix should be in another PR
caseyclements 1766750
Fixes to AsyncMongoDBSaver docstrings
caseyclements 87069e8
Added a couple lines to the README. It will be properly expanded in a…
caseyclements e647dba
Revert "pytest skipped: test_prebuilt_tool_chat as a fix should be in…
caseyclements 5219d3e
Addressed comments by @vbarda
caseyclements 5ebc64c
relax the requirement for having a thread ID in the config for alist
caseyclements 0871d6e
Reapply "pytest skipped: test_prebuilt_tool_chat so that we start wit…
caseyclements 5545743
formatting
caseyclements 5ef0954
Removed tests previously copied from langraph/tests
caseyclements aac8872
Made fix in put_writes
caseyclements e984a53
Copied latest langraph/test (test_pregel) into integration_tests
caseyclements 7bfe7b5
Updated pyproject.toml
caseyclements 4ba694b
Updated langgraph and langraph-checkpoint to main branch of langchain…
caseyclements 87906b7
Actually updated langgraph and langraph-checkpoint to main branch of …
caseyclements 5651c9f
Updated poetry.lock
caseyclements d504de4
Adjusted integration_tests to use relative imports
caseyclements 2a0d986
Formatted
caseyclements 6528cfd
Linting
caseyclements 1f728d8
Temporary change to poetry install with groups in tests
caseyclements 2fbf0aa
Temporarily removed libs/mongodb from CI to focus on langgraph-checkp…
caseyclements cd28d9a
Revert "Temporarily removed libs/mongodb from CI to focus on langgrap…
caseyclements f872518
Revert "Temporary change to poetry install with groups in tests"
caseyclements 754b9c8
Removed compile-integration-tests
caseyclements 68c924f
Renamed langchain_mongodb github actions
caseyclements 8c143cd
Merge branch 'main' into INTPYTHON-377-LANGGRAPH-CHECKPOINTER
caseyclements 17890aa
Updated check_diff script to take a specific lib, and added libs/mong…
caseyclements 037ce12
Unified style of pyproject with dev,test,lint,test_integration
caseyclements 069738e
Simplified project dependency groups and unified tests
caseyclements e953e26
Typos
caseyclements c0ade10
Typo in LIB_DIRS
caseyclements ab1c3c2
Remove irrelevant tests
caseyclements 1f9247c
Removed code duplication, using utils method prepare_metadata
caseyclements 4716887
Linting
caseyclements 69313b7
For linting, revert to using separate loads/dumps metadata methods, b…
caseyclements 6ee7287
Unused import
caseyclements d8d7d5c
nit fix
caseyclements File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
File renamed without changes.
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,10 @@ jobs: | |
|
||
- name: Install dependencies | ||
shell: bash | ||
run: poetry install --with test | ||
run: poetry install --with dev | ||
|
||
- name: Start MongoDB | ||
uses: supercharge/[email protected] | ||
|
||
- name: Run core tests | ||
shell: bash | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
# 🦜️🔗 LangChain MongoDB | ||
|
||
This repository contains 1 package with MongoDB integrations with LangChain: | ||
This is a Monorepo containing partner packages of MongoDB and LangChainAI. | ||
It includes integrations between MongoDB, Atlas, LangChain, and LangGraph. | ||
|
||
- [langchain-mongodb](https://pypi.org/project/langchain-mongodb/) | ||
It contains the following packages. | ||
|
||
- `langchain-mongodb` ([PyPI](https://pypi.org/project/langchain-mongodb/)) | ||
- `langgraph-checkpoint-mongodb` | ||
vbarda marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
.PHONY: test lint format help | ||
|
||
###################### | ||
# TESTING AND COVERAGE | ||
###################### | ||
|
||
test tests: | ||
poetry run pytest tests | ||
|
||
###################### | ||
# LINTING AND FORMATTING | ||
###################### | ||
|
||
# Define a variable for Python and notebook files. | ||
PYTHON_FILES=. | ||
MYPY_CACHE=.mypy_cache | ||
lint format: PYTHON_FILES=. | ||
lint_diff format_diff: PYTHON_FILES=$(shell git diff --name-only --relative --diff-filter=d main . | grep -E '\.py$$|\.ipynb$$') | ||
lint_package: PYTHON_FILES=langgraph | ||
lint_tests: PYTHON_FILES=tests | ||
lint_tests: MYPY_CACHE=.mypy_cache_test | ||
|
||
lint lint_diff lint_package lint_tests: | ||
poetry run ruff check . | ||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff format $(PYTHON_FILES) --diff | ||
[ "$(PYTHON_FILES)" = "" ] || poetry run ruff check --select I $(PYTHON_FILES) | ||
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) | ||
[ "$(PYTHON_FILES)" = "" ] || poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE) | ||
|
||
format format_diff: | ||
poetry run ruff format $(PYTHON_FILES) | ||
poetry run ruff check --select I --fix $(PYTHON_FILES) | ||
|
||
###################### | ||
# HELP | ||
###################### | ||
|
||
help: | ||
@echo '----' | ||
@echo 'format - run code formatters' | ||
@echo 'lint - run linters' | ||
@echo 'test - run unit tests' |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
# LangGraph Checkpoint MongoDB | ||
|
||
Implementation of LangGraph CheckpointSaver that uses MongoDB. | ||
|
||
## Usage | ||
|
||
```python | ||
from langgraph.checkpoint.mongodb import MongoDBSaver | ||
|
||
write_config = {"configurable": {"thread_id": "1", "checkpoint_ns": ""}} | ||
read_config = {"configurable": {"thread_id": "1"}} | ||
|
||
MONGODB_URI = "mongodb://localhost:27017" | ||
DB_NAME = "checkpoint_example" | ||
|
||
with MongoDBSaver.from_conn_string(MONGODB_URI, DB_NAME) as checkpointer: | ||
# call .setup() the first time you're using the checkpointer | ||
checkpointer.setup() | ||
checkpoint = { | ||
"v": 1, | ||
"ts": "2024-07-31T20:14:19.804150+00:00", | ||
"id": "1ef4f797-8335-6428-8001-8a1503f9b875", | ||
"channel_values": { | ||
"my_key": "meow", | ||
"node": "node" | ||
}, | ||
"channel_versions": { | ||
"__start__": 2, | ||
"my_key": 3, | ||
"start:node": 3, | ||
"node": 3 | ||
}, | ||
"versions_seen": { | ||
"__input__": {}, | ||
"__start__": { | ||
"__start__": 1 | ||
}, | ||
"node": { | ||
"start:node": 2 | ||
} | ||
}, | ||
"pending_sends": [], | ||
} | ||
|
||
# store checkpoint | ||
checkpointer.put(write_config, checkpoint, {}, {}) | ||
|
||
# load checkpoint | ||
checkpointer.get(read_config) | ||
|
||
# list checkpoints | ||
list(checkpointer.list(read_config)) | ||
``` | ||
|
||
### Async | ||
|
||
```python | ||
from langgraph.checkpoint.pymongo import AsyncMongoDBSaver | ||
|
||
async with AsyncMongoDBSaver.from_conn_string(MONGODB_URI) as checkpointer: | ||
checkpoint = { | ||
"v": 1, | ||
"ts": "2024-07-31T20:14:19.804150+00:00", | ||
"id": "1ef4f797-8335-6428-8001-8a1503f9b875", | ||
"channel_values": { | ||
"my_key": "meow", | ||
"node": "node" | ||
}, | ||
"channel_versions": { | ||
"__start__": 2, | ||
"my_key": 3, | ||
"start:node": 3, | ||
"node": 3 | ||
}, | ||
"versions_seen": { | ||
"__input__": {}, | ||
"__start__": { | ||
"__start__": 1 | ||
}, | ||
"node": { | ||
"start:node": 2 | ||
} | ||
}, | ||
"pending_sends": [], | ||
} | ||
|
||
# store checkpoint | ||
await checkpointer.aput(write_config, checkpoint, {}, {}) | ||
|
||
# load checkpoint | ||
await checkpointer.aget(read_config) | ||
|
||
# list checkpoints | ||
[c async for c in checkpointer.alist(read_config)] | ||
``` |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be re-enabled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I made that change, maybe. But it picks up, oh, 1909 errors that aren't related to my changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I opened https://jira.mongodb.org/browse/INTPYTHON-412 to follow up with restoring the lint.