Skip to content

Hook events

A hook callback subscribes to a specific event type and runs when that event fires during agent execution. This page is the reference for every event: when each one fires across the lifecycle, the full catalogue of event types, and which properties you can modify to change agent behavior. To write and register a callback, see Hooks.

The following diagram shows when hook events are emitted during a typical agent invocation where tools are invoked:

REQUEST START AGENT LOOP MODEL CALL TOOL EXECUTION EACH TOOL CALL REQUEST END TOOL CALLS RESULTS NO TOOL CALLS BeforeInvocationEvent MessageAddedEvent BeforeModelCallEvent AfterModelCallEvent MessageAddedEvent BeforeToolsEvent BeforeToolCallEvent AfterToolCallEvent AfterToolsEvent MessageAddedEvent AfterInvocationEvent

The following diagram shows when multi-agent hook events are emitted during orchestrator execution:

INITIALIZATION EACH INVOCATION INVOCATION START NODE EXECUTION INVOCATION END NEXT NODE MultiAgentInitializedEvent BeforeMultiAgentInvocationEvent BeforeNodeCallEvent AfterNodeCallEvent AfterMultiAgentInvocationEvent
EventDescription
AgentInitializedEventTriggered when an agent has been constructed and finished initialization at the end of the agent constructor.
BeforeInvocationEventTriggered at the beginning of a new agent invocation request
AfterInvocationEventTriggered at the end of an agent request, regardless of success or failure. Uses reverse callback ordering
MessageAddedEventTriggered when a message is added to the agent’s conversation history
BeforeModelCallEventTriggered before the model is invoked for inference
AfterModelCallEventTriggered after model invocation completes. Uses reverse callback ordering
BeforeToolsEventTriggered before tools are executed in a batch
BeforeToolCallEventTriggered before a tool is invoked
AfterToolCallEventTriggered after tool invocation completes. Uses reverse callback ordering
AfterToolsEventTriggered after tools are executed in a batch. Uses reverse callback ordering
MultiAgentInitializedEventTriggered when multi-agent orchestrator is initialized
BeforeMultiAgentInvocationEventTriggered before orchestrator execution starts
AfterMultiAgentInvocationEventTriggered after orchestrator execution completes. Uses reverse callback ordering
BeforeNodeCallEventTriggered before individual node execution starts
AfterNodeCallEventTriggered after individual node execution completes. Uses reverse callback ordering

Most event properties are read-only to prevent unintended modifications. However, certain properties can be modified to influence agent behavior:

  • Write and register a callback against any of these events in Hooks.
  • Bundle several callbacks together with Plugins.
  • See the Agent API Reference for complete method documentation: Python | TypeScript