redis_openai_agents.RedisCachingModel#
- class RedisCachingModel(model, redis_url='redis://localhost:6379', cache_prefix='model_cache', cache_ttl=3600, enable_semantic_cache=False, semantic_threshold=0.95)[source]#
Caching wrapper for OpenAI Agents SDK Model interface.
Wraps any Model implementation and adds 2-level caching: - Level 1: Exact match using hash of (system_instructions, input) - Level 2: Semantic similarity using vector embeddings (optional)
Caching is bypassed when: - Tools are provided (responses may depend on tool calls) - Handoffs are provided (complex agent interactions) - Output schema is provided (structured output validation)
- _model#
The underlying model being wrapped.
- cache_ttl#
Time-to-live for cache entries in seconds.
- enable_semantic_cache#
Whether to use semantic similarity caching.
- semantic_threshold#
Minimum similarity score for semantic cache hit.
Initialize the caching model wrapper.
- Parameters:
model (Any) – The underlying Model to wrap.
redis_url (str) – Redis connection URL.
cache_prefix (str) – Prefix for cache keys in Redis.
cache_ttl (int) – Time-to-live for cache entries in seconds.
enable_semantic_cache (bool) – Enable Level 2 semantic caching.
semantic_threshold (float) – Minimum similarity for semantic cache hit.
- __init__(model, redis_url='redis://localhost:6379', cache_prefix='model_cache', cache_ttl=3600, enable_semantic_cache=False, semantic_threshold=0.95)[source]#
Initialize the caching model wrapper.
- Parameters:
model (Any) – The underlying Model to wrap.
redis_url (str) – Redis connection URL.
cache_prefix (str) – Prefix for cache keys in Redis.
cache_ttl (int) – Time-to-live for cache entries in seconds.
enable_semantic_cache (bool) – Enable Level 2 semantic caching.
semantic_threshold (float) – Minimum similarity for semantic cache hit.
- Return type:
None
Methods
__init__(model[, redis_url, cache_prefix, ...])Initialize the caching model wrapper.
check_cache(system_instructions, input_data)Check if response is in cache.
close()Close Redis connection.
get_metrics()Get cache performance metrics.
get_response(system_instructions, input, ...)Get a response, checking cache first.
initialize()Initialize Redis connection and semantic cache if enabled.
stream_response(system_instructions, input, ...)Stream a response from the model.