openai-agents-session¶
Redis and DynamoDB session backends for openai-agents-python
Overview¶
openai-agents-session provides production-ready session storage backends for the OpenAI Agents Python SDK. It enables persistent conversation history across multiple interactions with your AI agents.
Features¶
- Redis Backend: High-performance in-memory storage with optional TTL
- DynamoDB Backend: Serverless, scalable cloud storage with automatic expiration
- Async Native: Built with
asynciofor non-blocking operations - Type Safe: Full type hints and PEP 561 compliant
- Zero Config: Works out of the box with sensible defaults
Quick Example¶
import redis.asyncio as redis
from agents import Agent, Runner
from openai_agents_session import RedisSession
# Create Redis client
client = redis.from_url("redis://localhost:6379")
# Create session with 1-hour TTL
session = RedisSession(
session_id="user-123",
redis_client=client,
ttl=3600,
)
# Use with OpenAI Agent
agent = Agent(name="Assistant", instructions="You are a helpful assistant.")
runner = Runner(agent=agent, session=session)
# Conversation persists across calls
result = await runner.run("Hello! My name is Alice.")
result = await runner.run("What's my name?") # Agent remembers "Alice"
Installation¶
Why Use This?¶
The default openai-agents-python stores conversation history in memory, which means:
- History is lost when your application restarts
- Each instance has its own isolated memory
- No way to resume conversations across sessions
With openai-agents-session, you get:
- Persistent storage that survives restarts
- Shared state across multiple application instances
- Automatic expiration with configurable TTL
- Scalable backends for production workloads
Next Steps¶
- Installation Guide - Detailed setup instructions
- Quick Start - Get up and running in minutes
- Redis Backend - Redis-specific configuration
- DynamoDB Backend - DynamoDB setup and usage