Environment:Openai Openai agents python Memory Extensions Dependencies
| Knowledge Sources | |
|---|---|
| Domains | Infrastructure, Memory |
| Last Updated | 2026-02-11 14:00 GMT |
Overview
Optional dependencies for persistent session memory backends: Redis, SQLAlchemy, Dapr, SQLite (async), and encrypted sessions.
Description
The Agents SDK supports multiple session memory backends beyond the default in-memory session. Each backend has its own optional dependency group. All memory extensions use lazy loading via `__getattr__` in the `extensions.memory` package, so imports only fail when you actually try to use a specific backend without its dependencies.
Usage
Use these dependencies when you need persistent conversation memory across agent runs. Choose the backend that matches your infrastructure: Redis for distributed caching, SQLAlchemy for relational databases, Dapr for microservice state stores, or EncryptedSession for at-rest encryption.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| Python | >= 3.9 | Same as core SDK |
| Redis Server | Redis 7+ | Only for RedisSession |
| PostgreSQL/MySQL | Any supported version | Only for SQLAlchemySession |
| Dapr Sidecar | Dapr runtime | Only for DaprSession |
Dependencies
Redis Session
- `redis` >= 7
SQLAlchemy Session
- `SQLAlchemy` >= 2.0
- `asyncpg` >= 0.29.0
Encrypted Session
- `cryptography` >= 45.0, < 46
Dapr Session
- `dapr` >= 1.16.0
- `grpcio` >= 1.60.0
SQLite Sessions (Advanced/Async)
- `aiosqlite` >= 0.21.0 (dev dependency, for AdvancedSQLiteSession and AsyncSQLiteSession)
Credentials
- Redis: Redis connection URL (host, port, password)
- SQLAlchemy: Database connection string (e.g., `postgresql+asyncpg://user:pass@host/db`)
- Dapr: Dapr sidecar configuration (state store component name)
- Encrypted: Encryption key (generated via `cryptography.fernet.Fernet.generate_key()`)
Quick Install
# Install specific backends as needed
pip install 'openai-agents[redis]'
pip install 'openai-agents[sqlalchemy]'
pip install 'openai-agents[encrypt]'
pip install 'openai-agents[dapr]'
# Or install multiple extras at once
pip install 'openai-agents[redis,encrypt]'
Code Evidence
Lazy loading pattern from `extensions/memory/__init__.py:37-47`:
def __getattr__(name: str) -> Any:
if name == "EncryptedSession":
try:
from .encrypt_session import EncryptedSession
return EncryptedSession
except ModuleNotFoundError:
raise ImportError(
"EncryptedSession requires the 'cryptography' extra. "
"Install it with: pip install 'openai-agents[encrypt]'"
)
Redis import guard from `extensions/memory/redis_session.py:29-35`:
try:
import redis.asyncio as redis
from redis.asyncio import Redis
except ImportError as e:
raise ImportError(
"RedisSession requires the 'redis' package. Install it with: pip install redis"
) from e
Dapr import guard from `extensions/memory/dapr_session.py:32-38`:
try:
from dapr.aio.clients import DaprClient
from dapr.clients.grpc._state import Concurrency, Consistency, StateOptions
except ImportError as e:
raise ImportError(
"DaprSession requires the 'dapr' package. Install it with: pip install dapr"
) from e
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `ImportError: EncryptedSession requires the 'cryptography' extra` | cryptography not installed | `pip install 'openai-agents[encrypt]'` |
| `ImportError: RedisSession requires the 'redis' package` | redis package not installed | `pip install 'openai-agents[redis]'` |
| `ImportError: SQLAlchemySession requires the 'sqlalchemy' extra` | SQLAlchemy not installed | `pip install 'openai-agents[sqlalchemy]'` |
| `ImportError: DaprSession requires the 'dapr' package` | dapr package not installed | `pip install 'openai-agents[dapr]'` |
Compatibility Notes
- Lazy loading: All memory extensions use `__getattr__` for lazy imports. You can safely import the `extensions.memory` package without having any backends installed.
- Dapr concurrency: DaprSession implements optimistic concurrency with etag-based conflict detection and automatic retry with exponential backoff.
- SQLite sessions: AdvancedSQLiteSession and AsyncSQLiteSession require `aiosqlite` which is a dev dependency (not in any optional extras group).