redis_openai_agents.middleware.SemanticRouterMiddleware#

class SemanticRouterMiddleware(router, *, responses=None, response_factory=None, auto_wrap=False)[source]#

Short-circuit the LLM call when the input matches a known intent.

Parameters:
  • router (SemanticRouter) – A SemanticRouter configured with the intents to recognize.

  • responses (Mapping[str, Any] | None) – Optional mapping from route name to canned response. Used when response_factory is not provided.

  • response_factory (ResponseFactory | None) – Optional callable that receives the RouteMatch and returns the response. Takes precedence over responses when supplied.

  • auto_wrap (bool)

Either responses or response_factory must yield a value for the short-circuit to trigger. If neither produces a response (for instance, an unmapped route name), the request delegates to the inner model.

__init__(router, *, responses=None, response_factory=None, auto_wrap=False)[source]#
Parameters:
  • router (SemanticRouter)

  • responses (Mapping[str, Any] | None)

  • response_factory (ResponseFactory | None)

  • auto_wrap (bool)

Return type:

None

Methods

__init__(router, *[, responses, ...])

awrap_model_call(request, handler)