redis_openai_agents.cached_tool#

cached_tool(*, name, redis_url='redis://localhost:6379', ttl=None, key_prefix='tool_cache', volatile_arg_names=None, ignored_arg_names=None, side_effect_prefixes=None)[source]#

Decorator that memoizes a callable’s return value in Redis.

Parameters:
  • name (str) – Logical tool name. Also used as part of the cache key and for checking side-effect prefixes.

  • redis_url (str) – Redis connection URL. The underlying Redis client is created once at decoration time and shared across calls.

  • ttl (int | None) – Optional TTL in seconds for cache entries. None keeps them indefinitely.

  • key_prefix (str) – Prefix for the Redis key; useful for namespacing across environments or deployments.

  • volatile_arg_names (Set[str] | None) – Set of argument names whose presence bypasses the cache entirely (even if the value is None). Use this for arguments that always change (timestamps, trace IDs that must be observed, random seeds). Defaults to DEFAULT_VOLATILE_ARG_NAMES.

  • ignored_arg_names (Set[str] | None) – Set of argument names to strip from the cache key before hashing. Use for values that do not change the result but vary between calls (trace IDs, request IDs).

  • side_effect_prefixes (tuple[str, ...] | None) – Tuple of name prefixes that mark the tool as side-effecting, in which case caching is disabled. Defaults to DEFAULT_SIDE_EFFECT_PREFIXES.

Returns:

A decorator.

Return type:

Callable[[T], T]