Commit 6b45d22
feat: skip model invocation when latest message contains ToolUse (strands-agents#1068)
* feat: skip model invocation when latest message contains ToolUse
- Add _has_tool_use_in_latest_message() helper function to detect ToolUse in latest message
- Modify event_loop_cycle() to skip model execution when ToolUse is detected
- Set stop_reason='tool_use' and use latest message directly for tool execution
- Add comprehensive test coverage with 10 test scenarios
- Maintain backward compatibility and existing functionality
- No performance impact, minimal overhead for detection
Resolves the requirement to skip model calls when the agent should directly
execute tools based on existing ToolUse messages in the conversation.
🤖 Assisted by the code-assist agent script
* fix: Check messages array size1 parent 6f603d2 commit 6b45d22
File tree
2 files changed
+46
-2
lines changed- src/strands/event_loop
- tests/strands/agent
2 files changed
+46
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
56 | 56 | | |
57 | 57 | | |
58 | 58 | | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
59 | 79 | | |
60 | 80 | | |
61 | 81 | | |
| |||
121 | 141 | | |
122 | 142 | | |
123 | 143 | | |
124 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
125 | 148 | | |
126 | 149 | | |
127 | 150 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2063 | 2063 | | |
2064 | 2064 | | |
2065 | 2065 | | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
| 2085 | + | |
| 2086 | + | |
2066 | 2087 | | |
2067 | 2088 | | |
2068 | 2089 | | |
| |||
0 commit comments