AgentTurnHooksMixin#
Build extensions, choose hooks, and manage request-scoped state. See the guide.
- class zett_agent.extensions.base.AgentTurnHooksMixin[源代码]#
Hooks around one model/tool turn inside a request.
A turn is one primary model call plus every tool invocation that call requested. One request runs one or more turns:
before_run() -> [before_turn() -> model step -> tools -> after_turn()] * n -> after_run()
Later turns follow steering or queued internal input that continues the same request. A request that uses no tools, receives no further input, and is not steered has exactly one turn, whose turn hooks sit between before_run and after_run.
- async before_turn(context)[源代码]#
Run before this turn's model call.
Runs after before_run() on the first turn and after the previous turn's after_turn() on later ones. Model request assembly, compaction, and before_model() follow this hook, so context edited here reaches the provider.
- 参数:
context (AgentRunContext)
- 返回类型:
None
- async after_turn(context, result)[源代码]#
Run once the turn's assistant message and tool results are settled.
resultis the assistant message that opened the turn: either the final answer, or the tool-calling message whose ToolMessages were appended. Every requested call is settled first, including calls that failed, and calls that steering skipped, which arrive as unsuccessful or skipped ToolMessages.Steering that interrupts a turn is accepted while the runtime settles that batch, so its UserMessage is already appended when this hook runs and the steering turn follows as the next turn.
A turn that never completed, because the request failed or was cancelled, has no after_turn call; use on_error and RunCancelledEvent for those paths.
- 参数:
context (AgentRunContext)
result (AssistantMessage)
- 返回类型:
None