MiddlewareHook#
Build extensions, choose hooks, and manage request-scoped state. See the guide.
- class zett_agent.extensions.base.MiddlewareHook[source]#
Wrap provider requests and local tool handlers for one extension.
Every
AgentExtensioninherits these hooks. Extensions form an onion in their existing priority order: the first extension is outermost and the last extension is closest to the provider or tool handler.One extension instance may serve concurrent sessions and parallel tool calls. Keep request-local data in local variables or on
context, not mutable instance attributes without synchronization.- async on_model_request(context, request, call_next)[source]#
Wrap one provider request and its complete streamed response.
Pass
request(or a dataclass replacement) tocall_next. The default closes the inner stream so cancellation reaches the provider.- Parameters:
context (AgentRunContext)
request (ModelRequest)
call_next (ModelRequestNext)
- Return type:
AsyncIterator[ModelEvent]
- async on_tool_call(context, call, call_next)[source]#
Wrap one registered local tool handler and return its
ToolResult.An extension may adjust
call.arguments, return without calling the next layer, transform its result, or raise into normal tool-failure handling.- Parameters:
context (AgentRunContext)
call (ToolCall)
call_next (ToolCallNext)
- Return type: