wrap_model_call(
func: _CallableReturningModelResponse[ContextT, ResponseT] | None = None,
*,
state_schema: type[| Name | Type | Description |
|---|---|---|
func | _CallableReturningModelResponse[ContextT, ResponseT] | None | Default: NoneFunction accepting (request, handler) that calls handler(request)
to execute the model and returns Request contains state and runtime. |
state_schema | type[StateT] | None | Default: NoneCustom state schema. Defaults to |
tools | list[BaseTool] | None | Default: None |
name | str | None | Default: None |
Create middleware with wrap_model_call hook from a function.
Converts a function with handler callback into middleware that can intercept model calls, implement retry logic, handle errors, and rewrite responses.
Additional tools to register with this middleware.
Middleware class name.
Defaults to function name.