v1.4.2
Bug Fix: Tool Exceptions Always Produce a tool_result
Fixes an issue where a tool that throws an exception would leave the conversation in an invalid state. The Anthropic API requires every tool_use block in an assistant message to have a corresponding tool_result block in the following user message. Previously, if $tool->execute() threw, the exception would bubble up without adding a tool_result, breaking the conversation.
Changes
- ToolExecutionTrait — wrapped tool lookup and execution in try-catch; exceptions now produce an error
ToolResultinstead of propagating - StreamingLoop::executeStreamingTools() — same fix applied
- ReactLoopTest — added
testToolExceptionProducesErrorToolResultto verify throwing tools still produce a valid errortool_result