strands.experimental.hooks
¶
Experimental hook functionality that has not yet reached stability.
strands.experimental.hooks.events
¶
Experimental hook events emitted as part of invoking Agents and BidiAgents.
This module defines the events that are emitted as Agents and BidiAgents run through the lifecycle of a request.
BidiAfterConnectionRestartEvent
dataclass
¶
Bases: BidiHookEvent
Event emitted after agent attempts to restart model connection after timeout.
Attribtues
exception: Populated if exception was raised during connection restart. None value means the restart was successful.
Source code in strands/experimental/hooks/events.py
208 209 210 211 212 213 214 215 216 217 | |
BidiAfterInvocationEvent
dataclass
¶
Bases: BidiHookEvent
Event triggered when BidiAgent ends a streaming session.
This event is fired after the BidiAgent has completed a streaming session, regardless of whether it completed successfully or encountered an error. Hook providers can use this event for cleanup, logging, or state persistence.
Note: This event uses reverse callback ordering, meaning callbacks registered later will be invoked first during cleanup.
This event is triggered at the end of agent.stop().
Source code in strands/experimental/hooks/events.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | |
should_reverse_callbacks
property
¶
True to invoke callbacks in reverse order.
BidiAfterToolCallEvent
dataclass
¶
Bases: BidiHookEvent
Event triggered after BidiAgent executes a tool.
This event is fired after the BidiAgent has finished executing a tool during a streaming session, regardless of whether the execution was successful or resulted in an error. Hook providers can use this event for cleanup, logging, or post-processing.
Note: This event uses reverse callback ordering, meaning callbacks registered later will be invoked first during cleanup.
Attributes:
| Name | Type | Description |
|---|---|---|
selected_tool |
AgentTool | None
|
The tool that was invoked. It may be None if tool lookup failed. |
tool_use |
ToolUse
|
The tool parameters that were passed to the tool invoked. |
invocation_state |
dict[str, Any]
|
Keyword arguments that were passed to the tool. |
result |
ToolResult
|
The result of the tool invocation. Either a ToolResult on success or an Exception if the tool execution failed. |
exception |
Exception | None
|
Exception if the tool execution failed, None if successful. |
cancel_message |
str | None
|
The cancellation message if the user cancelled the tool call. |
Source code in strands/experimental/hooks/events.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 | |
should_reverse_callbacks
property
¶
True to invoke callbacks in reverse order.
BidiAgentInitializedEvent
dataclass
¶
Bases: BidiHookEvent
Event triggered when a BidiAgent has finished initialization.
This event is fired after the BidiAgent has been fully constructed and all built-in components have been initialized. Hook providers can use this event to perform setup tasks that require a fully initialized agent.
Source code in strands/experimental/hooks/events.py
46 47 48 49 50 51 52 53 54 55 | |
BidiBeforeConnectionRestartEvent
dataclass
¶
Bases: BidiHookEvent
Event emitted before agent attempts to restart model connection after timeout.
Attributes:
| Name | Type | Description |
|---|---|---|
timeout_error |
BidiModelTimeoutError
|
Timeout error reported by the model. |
Source code in strands/experimental/hooks/events.py
197 198 199 200 201 202 203 204 205 | |
BidiBeforeInvocationEvent
dataclass
¶
Bases: BidiHookEvent
Event triggered when BidiAgent starts a streaming session.
This event is fired before the BidiAgent begins a streaming session, before any model connection or audio processing occurs. Hook providers can use this event to perform session-level setup, logging, or validation.
This event is triggered at the beginning of agent.start().
Source code in strands/experimental/hooks/events.py
58 59 60 61 62 63 64 65 66 67 68 69 | |
BidiBeforeToolCallEvent
dataclass
¶
Bases: BidiHookEvent
Event triggered before BidiAgent executes a tool.
This event is fired just before the BidiAgent executes a tool during a streaming session, allowing hook providers to inspect, modify, or replace the tool that will be executed. The selected_tool can be modified by hook callbacks to change which tool gets executed.
Attributes:
| Name | Type | Description |
|---|---|---|
selected_tool |
AgentTool | None
|
The tool that will be invoked. Can be modified by hooks to change which tool gets executed. This may be None if tool lookup failed. |
tool_use |
ToolUse
|
The tool parameters that will be passed to selected_tool. |
invocation_state |
dict[str, Any]
|
Keyword arguments that will be passed to the tool. |
cancel_tool |
bool | str
|
A user defined message that when set, will cancel the tool call.
The message will be placed into a tool result with an error status. If set to |
Source code in strands/experimental/hooks/events.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | |
BidiHookEvent
dataclass
¶
Bases: BaseHookEvent
Base class for BidiAgent hook events.
Attributes:
| Name | Type | Description |
|---|---|---|
agent |
BidiAgent
|
The BidiAgent instance that triggered this event. |
Source code in strands/experimental/hooks/events.py
35 36 37 38 39 40 41 42 43 | |
BidiInterruptionEvent
dataclass
¶
Bases: BidiHookEvent
Event triggered when model generation is interrupted.
This event is fired when the user interrupts the assistant (e.g., by speaking during the assistant's response) or when an error causes interruption. This is specific to bidirectional streaming and doesn't exist in standard agents.
Hook providers can use this event to log interruptions, implement custom interruption handling, or trigger cleanup logic.
Attributes:
| Name | Type | Description |
|---|---|---|
reason |
Literal['user_speech', 'error']
|
The reason for the interruption ("user_speech" or "error"). |
interrupted_response_id |
str | None
|
Optional ID of the response that was interrupted. |
Source code in strands/experimental/hooks/events.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | |
BidiMessageAddedEvent
dataclass
¶
Bases: BidiHookEvent
Event triggered when BidiAgent adds a message to the conversation.
This event is fired whenever the BidiAgent adds a new message to its internal message history, including user messages (from transcripts), assistant responses, and tool results. Hook providers can use this event for logging, monitoring, or implementing custom message processing logic.
Note: This event is only triggered for messages added by the framework itself, not for messages manually added by tools or external code.
Attributes:
| Name | Type | Description |
|---|---|---|
message |
Message
|
The message that was added to the conversation history. |
Source code in strands/experimental/hooks/events.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
strands.experimental.hooks.multiagent
¶
Multi-agent hook events and utilities.
Provides event classes for hooking into multi-agent orchestrator lifecycle.
strands.experimental.hooks.multiagent.events
¶
Multi-agent execution lifecycle events for hook system integration.
These events are fired by orchestrators (Graph/Swarm) at key points so hooks can persist, monitor, or debug execution. No intermediate state model is used—hooks read from the orchestrator directly.
AfterMultiAgentInvocationEvent
dataclass
¶
Bases: BaseHookEvent
Event triggered after orchestrator execution completes.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
MultiAgentBase
|
The multi-agent orchestrator instance |
invocation_state |
dict[str, Any] | None
|
Configuration that user passes in |
Source code in strands/experimental/hooks/multiagent/events.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
should_reverse_callbacks
property
¶
True to invoke callbacks in reverse order.
AfterNodeCallEvent
dataclass
¶
Bases: BaseHookEvent
Event triggered after individual node execution completes.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
MultiAgentBase
|
The multi-agent orchestrator instance |
node_id |
str
|
ID of the node that just completed execution |
invocation_state |
dict[str, Any] | None
|
Configuration that user passes in |
Source code in strands/experimental/hooks/multiagent/events.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 | |
should_reverse_callbacks
property
¶
True to invoke callbacks in reverse order.
BeforeMultiAgentInvocationEvent
dataclass
¶
Bases: BaseHookEvent
Event triggered before orchestrator execution starts.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
MultiAgentBase
|
The multi-agent orchestrator instance |
invocation_state |
dict[str, Any] | None
|
Configuration that user passes in |
Source code in strands/experimental/hooks/multiagent/events.py
72 73 74 75 76 77 78 79 80 81 82 | |
BeforeNodeCallEvent
dataclass
¶
Bases: BaseHookEvent
Event triggered before individual node execution starts.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
MultiAgentBase
|
The multi-agent orchestrator instance |
node_id |
str
|
ID of the node about to execute |
invocation_state |
dict[str, Any] | None
|
Configuration that user passes in |
cancel_node |
bool | str
|
A user defined message that when set, will cancel the node execution with status FAILED.
The message will be emitted under a MultiAgentNodeCancel event. If set to |
Source code in strands/experimental/hooks/multiagent/events.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
MultiAgentInitializedEvent
dataclass
¶
Bases: BaseHookEvent
Event triggered when multi-agent orchestrator initialized.
Attributes:
| Name | Type | Description |
|---|---|---|
source |
MultiAgentBase
|
The multi-agent orchestrator instance |
invocation_state |
dict[str, Any] | None
|
Configuration that user passes in |
Source code in strands/experimental/hooks/multiagent/events.py
17 18 19 20 21 22 23 24 25 26 27 | |