Commit 8e32040
committed
feat: move hook event firing into reduce_context methods
Fire BeforeReduceContextEvent and AfterReduceContextEvent inside each
reduce_context() implementation instead of at the call site in the agent's
event loop. This ensures hooks are triggered for all reduce_context calls:
- From ContextWindowOverflowException handling in event loop
- From ConversationManager.apply_management() for proactive reduction
Hook callbacks are now synchronous (invoke_callbacks) since reduce_context
is synchronous and may be called from sync contexts.
Files modified:
- agent.py: Remove hook firing from _execute_event_loop_cycle()
- sliding_window_conversation_manager.py: Add sync hook calls
- summarizing_conversation_manager.py: Add sync hook calls
- null_conversation_manager.py: Add sync before hook
Addresses reviewer feedback: hooks now fire regardless of reduction source.1 parent a6732f1 commit 8e32040
File tree
4 files changed
+17
-7
lines changed- src/strands/agent
- conversation_manager
4 files changed
+17
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
39 | 38 | | |
40 | 39 | | |
41 | | - | |
42 | 40 | | |
43 | 41 | | |
44 | 42 | | |
| |||
965 | 963 | | |
966 | 964 | | |
967 | 965 | | |
968 | | - | |
969 | | - | |
970 | 966 | | |
971 | 967 | | |
972 | 968 | | |
973 | | - | |
974 | | - | |
975 | 969 | | |
976 | 970 | | |
977 | 971 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
| |||
Lines changed: 7 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
174 | 177 | | |
175 | 178 | | |
176 | 179 | | |
| |||
213 | 216 | | |
214 | 217 | | |
215 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
216 | 222 | | |
217 | 223 | | |
218 | 224 | | |
| |||
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
138 | 142 | | |
139 | 143 | | |
140 | 144 | | |
| |||
171 | 175 | | |
172 | 176 | | |
173 | 177 | | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
174 | 181 | | |
175 | 182 | | |
176 | 183 | | |
| |||
0 commit comments