Skip to content

Commit 01b9fba

Browse files
committed
add cosmos db sample for checkpointer
1 parent 549915a commit 01b9fba

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/oss/langchain/short-term-memory.mdx

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,40 @@ const checkpointer = PostgresSaver.fromConnString(DB_URI);
107107
```
108108
:::
109109

110+
You can also use Azure Cosmos DB as a checkpoint saver:
111+
112+
:::python
113+
```shell
114+
pip install langgraph-checkpoint-cosmosdb
115+
```
116+
117+
```python
118+
from langchain.agents import create_agent
119+
from langgraph_checkpoint_cosmosdb import CosmosDBSaver # [!code highlight]
120+
import os
121+
122+
# Set environment variables for authentication
123+
os.environ["COSMOSDB_ENDPOINT"] = "your_cosmosdb_endpoint"
124+
os.environ["COSMOSDB_KEY"] = "your_cosmosdb_key"
125+
126+
# Database and Container are created if they don't exist
127+
checkpointer = CosmosDBSaver( # [!code highlight]
128+
database_name="your_database", # [!code highlight]
129+
container_name="your_container" # [!code highlight]
130+
) # [!code highlight]
131+
132+
agent = create_agent(
133+
"gpt-5",
134+
[get_user_info],
135+
checkpointer=checkpointer, # [!code highlight]
136+
)
137+
```
138+
139+
<Note>
140+
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.
141+
</Note>
142+
:::
143+
110144

111145
## Customizing agent memory
112146

0 commit comments

Comments
 (0)