AgentModelHooksMixin#

Build extensions, choose hooks, and manage request-scoped state. See the guide.

class zett_agent.extensions.base.AgentModelHooksMixin[源代码]#

Hooks immediately before and after each primary model invocation.

async before_model(context, request)[源代码]#

Inspect the current request before preprocessing a primary model call.

Request fields are frozen. Change messages through AgentRunContext.add_message() or AgentRunContext.replace_messages(), local tools through context.tools, and provider tools through context.server_tools; the runtime rebuilds these fields before the next hook and before calling the provider. This is a shallow request view, not an immutable copy of each message or tool definition.

示例

Inspect the tools offered in this iteration:

async def before_model(self, context, request):
    offered = {definition.name for definition in request.tools}
    if "write_file" in offered:
        context.add_message(
            SystemMessage(content="Read existing files before editing."),
        )
参数:
返回类型:

None

async after_model(context, response)[源代码]#

Run after the complete assistant message is appended.

参数:
返回类型:

None