Commit 7d7f1f2
committed
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 script1 parent 78c59b9 commit 7d7f1f2
File tree
2 files changed
+45
-2
lines changed- src/strands/event_loop
- tests/strands/agent
2 files changed
+45
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
56 | 75 | | |
57 | 76 | | |
58 | 77 | | |
| |||
111 | 130 | | |
112 | 131 | | |
113 | 132 | | |
114 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
115 | 137 | | |
116 | 138 | | |
117 | 139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2061 | 2061 | | |
2062 | 2062 | | |
2063 | 2063 | | |
| 2064 | + | |
| 2065 | + | |
| 2066 | + | |
| 2067 | + | |
| 2068 | + | |
| 2069 | + | |
| 2070 | + | |
| 2071 | + | |
| 2072 | + | |
| 2073 | + | |
| 2074 | + | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
| 2081 | + | |
| 2082 | + | |
| 2083 | + | |
| 2084 | + | |
0 commit comments