Redis provides enhanced features for Empathy Framework:
- Session Management: Fast, TTL-based working memory for agent coordination
- Real-time Coordination: Pub/Sub messaging between agents
- Caching: Two-tier caching (memory + Redis) for performance
- Task Queues: Distributed task management
- Audit Trails: Redis Streams for event logging
Redis is OPTIONAL - The framework works perfectly without it using in-memory mock mode.
# Using Homebrew (recommended)
brew install redis
# Start Redis service
brew services start redis
# Verify Redis is running
redis-cli ping # Should return: PONGAdd to your .env file:
# Redis Configuration (Local Development)
REDIS_ENABLED=true
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
# REDIS_PASSWORD= # Leave empty if no passwordfrom empathy_os.memory.short_term import RedisShortTermMemory
from empathy_os.memory.types import AgentCredentials, AccessTier
# Initialize Redis
memory = RedisShortTermMemory()
print(f"Redis connected: {memory.client is not None}")
# Test basic operation
creds = AgentCredentials("agent_1", AccessTier.CONTRIBUTOR)
memory.stash("test_key", {"data": "Hello Redis!"}, creds)
data = memory.retrieve("test_key", creds)
print(f"Retrieved: {data}")| Variable | Default | Description |
|---|---|---|
REDIS_ENABLED |
false |
Enable/disable Redis (true/false) |
REDIS_HOST |
localhost |
Redis server hostname |
REDIS_PORT |
6379 |
Redis server port |
REDIS_DB |
0 |
Redis database number (0-15) |
REDIS_PASSWORD |
None | Redis password (if required) |
from empathy_os.memory.short_term import RedisShortTermMemory
from empathy_os.memory.types import RedisConfig
# Option 1: Using environment variables (recommended)
memory = RedisShortTermMemory()
# Option 2: Direct configuration
config = RedisConfig(
host="localhost",
port=6379,
db=0,
password=None,
ssl=False, # Enable for managed Redis services
)
memory = RedisShortTermMemory(config=config)
# Option 3: Force mock mode for testing
memory = RedisShortTermMemory(use_mock=True)from empathy_os.memory.types import AccessTier
# Different access tiers
reader = AgentCredentials("agent_reader", AccessTier.READER)
contributor = AgentCredentials("agent_contributor", AccessTier.CONTRIBUTOR)
coordinator = AgentCredentials("agent_coordinator", AccessTier.COORDINATOR)from empathy_os.memory.types import TTLStrategy
# Data expires after 1 hour
memory.stash("temp_data", {"value": 42}, creds, ttl_seconds=3600)
# Use TTL strategies
strategy = TTLStrategy.MEDIUM # 1 hour
memory.stash("working_data", data, creds, ttl_strategy=strategy)# Subscribe to agent signals
def on_message(msg):
print(f"Received: {msg}")
memory.subscribe("agent_signals", on_message)
# Publish from another agent
memory.publish("agent_signals", {"event": "task_complete"}, creds)# Stash multiple items efficiently
items = [
("key1", {"data": 1}),
("key2", {"data": 2}),
("key3", {"data": 3}),
]
memory.stash_batch(items, creds)
# Retrieve multiple items
keys = ["key1", "key2", "key3"]
results = memory.retrieve_batch(keys, creds)If you download Empathy Framework for the first time:
- Redis is NOT required - The framework works out of the box
- Mock mode is automatic - In-memory storage is used by default
- No setup needed - Just start using the framework
Enable Redis when you need:
- ✅ Multi-agent coordination across processes
- ✅ Persistent session management
- ✅ Real-time pub/sub messaging
- ✅ Production-grade caching
- ✅ Distributed task queues
# Check if Redis is running
redis-cli ping
# If not running, start it
brew services start redis
# Check Redis logs
tail -f /opt/homebrew/var/log/redis.log# Check Redis configuration
redis-cli CONFIG GET requirepass
# If password is set, add to .env
REDIS_PASSWORD=your_password_here# Check what's using port 6379
lsof -i :6379
# Use a different port
REDIS_PORT=6380For production, use managed Redis services:
- AWS ElastiCache: Enterprise-grade, managed Redis
- Redis Cloud: Official Redis hosting
- Google Cloud Memorystore: GCP-integrated Redis
# Enable SSL/TLS
REDIS_ENABLED=true
REDIS_HOST=your-redis.cloud.redislabs.com
REDIS_PORT=6379
REDIS_PASSWORD=your_secure_password
REDIS_SSL=trueconfig = RedisConfig(
host="redis-primary.example.com",
port=6379,
password="secure_password",
ssl=True,
retry_max_attempts=5, # Retry on failure
retry_base_delay=0.1, # Start with 100ms
retry_max_delay=5.0, # Max 5 seconds between retries
)memory = RedisShortTermMemory()
print(f"Total requests: {memory.metrics.total_requests}")
print(f"Success rate: {memory.metrics.success_rate}%")
print(f"Average latency: {memory.metrics.latency_avg_ms}ms")
print(f"Retries: {memory.metrics.retries_total}")# Monitor all commands
redis-cli MONITOR
# Check memory usage
redis-cli INFO memory
# List all keys
redis-cli KEYS "empathy:*"
# Get key value
redis-cli GET empathy:working:my_key- Optional: Redis is NOT required for Empathy Framework
- Easy Setup: 3 steps to enable on macOS
- Automatic Fallback: Mock mode when Redis is disabled
- Production Ready: SSL, retries, high availability support
- Well Tested: 4 of 5 Redis initialization tests passing
For questions or issues, see: GitHub Issues