-
Notifications
You must be signed in to change notification settings - Fork 665
add cosmos db sample for checkpointer #1313
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -107,6 +107,40 @@ const checkpointer = PostgresSaver.fromConnString(DB_URI); | |||||||||||||||||||
| ``` | ||||||||||||||||||||
| ::: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| You can also use Azure Cosmos DB as a checkpoint saver: | ||||||||||||||||||||
|
|
||||||||||||||||||||
| :::python | ||||||||||||||||||||
| ```shell | ||||||||||||||||||||
| pip install langgraph-checkpoint-cosmosdb | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| ```python | ||||||||||||||||||||
| from langchain.agents import create_agent | ||||||||||||||||||||
| from langgraph_checkpoint_cosmosdb import CosmosDBSaver # [!code highlight] | ||||||||||||||||||||
| import os | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Set environment variables for authentication | ||||||||||||||||||||
| os.environ["COSMOSDB_ENDPOINT"] = "your_cosmosdb_endpoint" | ||||||||||||||||||||
| os.environ["COSMOSDB_KEY"] = "your_cosmosdb_key" | ||||||||||||||||||||
|
|
||||||||||||||||||||
| # Database and Container are created if they don't exist | ||||||||||||||||||||
| checkpointer = CosmosDBSaver( # [!code highlight] | ||||||||||||||||||||
| database_name="your_database", # [!code highlight] | ||||||||||||||||||||
| container_name="your_container" # [!code highlight] | ||||||||||||||||||||
| ) # [!code highlight] | ||||||||||||||||||||
|
|
||||||||||||||||||||
| agent = create_agent( | ||||||||||||||||||||
| "gpt-5", | ||||||||||||||||||||
| [get_user_info], | ||||||||||||||||||||
| checkpointer=checkpointer, # [!code highlight] | ||||||||||||||||||||
| ) | ||||||||||||||||||||
| ``` | ||||||||||||||||||||
|
|
||||||||||||||||||||
| <Note> | ||||||||||||||||||||
| Azure Cosmos DB checkpointer supports both sync and async operations. If the database and container already exist, you can use default RBAC credentials (e.g., `az login`) instead of setting the endpoint and key. | ||||||||||||||||||||
| </Note> | ||||||||||||||||||||
| ::: | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
|
Comment on lines
+139
to
144
|
||||||||||||||||||||
| <Note> | |
| Azure Cosmos DB checkpointer supports both sync and async operations. If the database and container already exist, you can use default RBAC credentials (e.g., `az login`) instead of setting the endpoint and key. | |
| </Note> | |
| ::: | |
| ::: | |
| <Note> | |
| Azure Cosmos DB checkpointer supports both sync and async operations. If the database and container already exist, you can use default RBAC credentials (e.g., `az login`) instead of setting the endpoint and key. | |
| </Note> |
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.
The Cosmos DB example should follow the same pattern as the PostgreSQL example above (lines 92-98) by using a context manager. Consider wrapping the CosmosDBSaver initialization in a
withstatement to ensure proper resource cleanup, unless the CosmosDBSaver doesn't support context managers.