redis_openai_agents.with_metrics#

with_metrics(metrics, token_extractor=None)[source]#

Decorator that records metrics for a run function.

Records latency, cache hit status, and token counts.

Parameters:
  • metrics (AgentMetrics) – AgentMetrics instance

  • token_extractor (Callable[[Any], tuple[int, int]] | None) – Optional function to extract (input_tokens, output_tokens)

Returns:

Decorated function

Return type:

Callable[[Callable[[…], T]], Callable[[…], T]]