wrap_model_call(
func: _CallableReturningModelResponse[StateT, ContextT, ResponseT] | None = None,
*,
state_schema| Name | Type | Description |
|---|---|---|
func | _CallableReturningModelResponse[StateT, 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: None |
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.
Custom state schema.
Defaults to AgentState.
Additional tools to register with this middleware.
Middleware class name.
Defaults to function name.