strands.experimental
¶
Experimental features.
This module implements experimental features that are subject to change in future revisions without notice.
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.
This module defines the events that are emitted as Agents run through the lifecycle of a request.
AfterModelInvocationEvent
dataclass
¶
Bases: HookEvent
Event triggered after the model invocation completes.
This event is fired after the agent has finished calling the model, regardless of whether the invocation 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.
Note: This event is not fired for invocations to structured_output.
Attributes:
Name | Type | Description |
---|---|---|
stop_response |
Optional[ModelStopResponse]
|
The model response data if invocation was successful, None if failed. |
exception |
Optional[Exception]
|
Exception if the model invocation failed, None if successful. |
Source code in strands/experimental/hooks/events.py
should_reverse_callbacks
property
¶
True to invoke callbacks in reverse order.
ModelStopResponse
dataclass
¶
Model response data from successful invocation.
Attributes:
Name | Type | Description |
---|---|---|
stop_reason |
StopReason
|
The reason the model stopped generating. |
message |
Message
|
The generated message from the model. |
Source code in strands/experimental/hooks/events.py
AfterToolInvocationEvent
dataclass
¶
Bases: HookEvent
Event triggered after a tool invocation completes.
This event is fired after the agent has finished executing a tool, 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 |
Optional[AgentTool]
|
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. |
Source code in strands/experimental/hooks/events.py
should_reverse_callbacks
property
¶
True to invoke callbacks in reverse order.
BeforeModelInvocationEvent
dataclass
¶
Bases: HookEvent
Event triggered before the model is invoked.
This event is fired just before the agent calls the model for inference, allowing hook providers to inspect or modify the messages and configuration that will be sent to the model.
Note: This event is not fired for invocations to structured_output.
Source code in strands/experimental/hooks/events.py
BeforeToolInvocationEvent
dataclass
¶
Bases: HookEvent
Event triggered before a tool is invoked.
This event is fired just before the agent executes a tool, 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 |
Optional[AgentTool]
|
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. |