Skip to main content
MongoDB stores agent state as flexible documents — ideal for nested metadata and schema-less data.
The user sets preferences; MongoDB stores flexible agent state as documents.

Quick Start

1

Simple Usage

2

With Configuration

Use MongoDBStateStore directly for collection and database control:

How It Works

MongoDB is a state store — it holds key-value agent state, not full conversation history. Pair it with a SQL conversation backend when you need both.

Configuration Options

URL formats

For async workloads, use create_state_store("async_mongodb", ...).

Best Practices

Use database_url for chat history and state_url for fast agent state — MongoDB handles state only.
Pass ttl on set() for session-scoped preferences that should expire automatically.
Append replicaSet= to the URL for high availability.
Set collection="prod_state" vs collection="staging_state" to isolate environments on one cluster.

Redis State Store

In-memory state for sub-millisecond access

Database Persistence

Overview of conversation and state backends