You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user-guide/concepts/agents/hooks.md
+24-34Lines changed: 24 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ Hooks enable use cases such as:
16
16
17
17
## Basic Usage
18
18
19
-
Hook callbacks are registered against specific event types and receive strongly-typed event objects when those events occur during agent execution. Each event carries relevant data for that stage of the agent lifecycle - for example, `BeforeInvocationEvent` includes agent and request details, while `BeforeToolInvocationEvent` provides tool information and parameters.
19
+
Hook callbacks are registered against specific event types and receive strongly-typed event objects when those events occur during agent execution. Each event carries relevant data for that stage of the agent lifecycle - for example, `BeforeInvocationEvent` includes agent and request details, while `BeforeToolCallEvent` provides tool information and parameters.
@@ -103,25 +103,16 @@ The hooks system provides events for different stages of agent execution:
103
103
|`BeforeInvocationEvent`| Triggered at the beginning of a new agent request (`__call__`, `stream_async`, or `structured_output`) |
104
104
|`AfterInvocationEvent`| Triggered at the end of an agent request, regardless of success or failure. Uses reverse callback ordering |
105
105
|`MessageAddedEvent`| Triggered when a message is added to the agent's conversation history |
106
-
107
-
Additional *experimental events* are also available:
108
-
109
-
!!! note "Experimental events are subject to change"
110
-
111
-
These events are exposed experimentally in order to gather feedback and refine the public contract. Because they are experimental, they are subject to change between releases.
112
-
113
-
| Experimental Event | Description |
114
-
|------------------------------|-------------|
115
-
|`BeforeModelInvocationEvent`| Triggered before the model is invoked for inference |
116
-
|`AfterModelInvocationEvent`| Triggered after model invocation completes. Uses reverse callback ordering |
117
-
|`BeforeToolInvocationEvent`| Triggered before a tool is invoked. |
Most event properties are read-only to prevent unintended modifications. However, certain properties can be modified to influence agent behavior. For example, `BeforeToolInvocationEvent.selected_tool` allows you to change which tool gets executed, while `AfterToolInvocationEvent.result` enables modification of tool results.
115
+
Most event properties are read-only to prevent unintended modifications. However, certain properties can be modified to influence agent behavior. For example, `BeforeToolCallEvent.selected_tool` allows you to change which tool gets executed, while `AfterToolCallEvent.result` enables modification of tool results.
125
116
126
117
### Callback Ordering
127
118
@@ -174,8 +165,7 @@ Enforce specific arguments for tools, ensuring they always use particular values
174
165
175
166
```python
176
167
from typing import Any
177
-
from strands.hooks import HookProvider, HookRegistry
178
-
from strands.experimental.hooks import BeforeToolInvocationEvent
168
+
from strands.hooks import HookProvider, HookRegistry, BeforeToolCallEvent
179
169
180
170
classConstantToolArguments(HookProvider):
181
171
"""Use constant argument values for specific parameters of a tool."""
@@ -192,9 +182,9 @@ class ConstantToolArguments(HookProvider):
0 commit comments