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:

flowchart LR
subgraph Start["Request Start Events"]
direction TB
BeforeInvocationEvent["BeforeInvocationEvent"]
StartMessage["MessageAddedEvent"]
BeforeInvocationEvent --> StartMessage
end
subgraph Model["Model Events"]
direction TB
BeforeModelCallEvent["BeforeModelCallEvent"]
AfterModelCallEvent["AfterModelCallEvent"]
ModelMessage["MessageAddedEvent"]
BeforeModelCallEvent --> AfterModelCallEvent
AfterModelCallEvent --> ModelMessage
end
subgraph Tool["Tool Events"]
direction TB
BeforeToolsEvent["BeforeToolsEvent"]
BeforeToolCallEvent["BeforeToolCallEvent"]
AfterToolCallEvent["AfterToolCallEvent"]
AfterToolsEvent["AfterToolsEvent"]
ToolMessage["MessageAddedEvent"]
BeforeToolsEvent --> BeforeToolCallEvent
BeforeToolCallEvent --> AfterToolCallEvent
AfterToolCallEvent --> AfterToolsEvent
AfterToolsEvent --> ToolMessage
end
subgraph End["Request End Events"]
direction TB
AfterInvocationEvent["AfterInvocationEvent"]
end
Start --> Model
Model <--> Tool
Tool --> End

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

flowchart LR
subgraph Init["Initialization"]
direction TB
MultiAgentInitializedEvent["MultiAgentInitializedEvent"]
end
subgraph Invocation["Invocation Lifecycle"]
direction TB
BeforeMultiAgentInvocationEvent["BeforeMultiAgentInvocationEvent"]
AfterMultiAgentInvocationEvent["AfterMultiAgentInvocationEvent"]
BeforeMultiAgentInvocationEvent --> NodeExecution
NodeExecution --> AfterMultiAgentInvocationEvent
end
subgraph NodeExecution["Node Execution (Repeated)"]
direction TB
BeforeNodeCallEvent["BeforeNodeCallEvent"]
AfterNodeCallEvent["AfterNodeCallEvent"]
BeforeNodeCallEvent --> AfterNodeCallEvent
end
Init --> Invocation
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