AgentModelHooksMixin#

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

class zett_agent.extensions.base.AgentModelHooksMixin[source]#

Hooks immediately before and after each primary model invocation.

async before_model(context, request)[source]#

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.

Examples

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."),
        )
Parameters:
Return type:

None

async after_model(context, response)[source]#

Run after the complete assistant message is appended.

Parameters:
Return type:

None