Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/oss/langchain/short-term-memory.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
Comment on lines +127 to +136
Copy link

Copilot AI Nov 6, 2025

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 with statement to ensure proper resource cleanup, unless the CosmosDBSaver doesn't support context managers.

Suggested change
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]
)
with CosmosDBSaver( # [!code highlight]
database_name="your_database", # [!code highlight]
container_name="your_container" # [!code highlight]
) as checkpointer: # [!code highlight]
agent = create_agent(
"gpt-5",
[get_user_info],
checkpointer=checkpointer, # [!code highlight]
)

Copilot uses AI. Check for mistakes.
```

<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
Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The note is placed inside the :::python block, which means it will only appear in the Python-specific documentation. Since this is general information about Azure Cosmos DB (not Python-specific), consider placing it outside the :::python block to ensure it appears in all documentation versions.

Suggested change
<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>

Copilot uses AI. Check for mistakes.
## Customizing agent memory

Expand Down