Commit ca9f8de
committed
fix(server): don't raise when tool_use is not followed by tool_result
Closes #2960
Per SEP-1577, tool_result blocks MUST be preceded by a tool_use block, but
there is no requirement that a tool_use MUST be followed by a tool_result. A
plain text response after a tool_use is valid.
The ID-matching check in validate_tool_use_result_messages ran whenever the
previous message contained a tool_use, regardless of whether the last message
actually had any tool_result blocks. With no tool_result blocks present,
tool_result_ids was empty and never matched the non-empty tool_use_ids,
raising a false 'ids ... do not match' ValueError.
Gate the check on has_tool_results so it only runs when the last message
actually contains tool_result blocks.
Adds a regression test that fails without the fix.1 parent a527142 commit ca9f8de
2 files changed
Lines changed: 25 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
83 | | - | |
| 83 | + | |
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
0 commit comments