MiddlewareHook#
Build extensions, choose hooks, and manage request-scoped state. See the guide.
- class zett_agent.extensions.base.MiddlewareHook[源代码]#
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)[源代码]#
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.- 参数:
context (AgentRunContext)
request (ModelRequest)
call_next (ModelRequestNext)
- 返回类型:
AsyncIterator[ModelEvent]
- async on_tool_call(context, call, call_next)[源代码]#
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.- 参数:
context (AgentRunContext)
call (ToolCall)
call_next (ToolCallNext)
- 返回类型: