v1.4.6
Bug Fix
Fix orphaned tool_use blocks causing API validation errors
The agent loops (ReactLoop, PlanExecuteLoop, ReflectionLoop) previously relied on stop_reason === 'tool_use' to decide whether to add tool_result blocks. When the Claude API returned tool_use blocks with a different stop_reason (e.g. max_tokens), no tool_result was added, leaving orphaned tool_use blocks in the message array. The next API call then failed with:
messages.N: tool_use ids were found without tool_result blocks immediately after
Changes
- Added
contentHasToolUse()helper toToolExecutionTraitthat inspects response content directly ReactLoopnow always addstool_resultblocks when content containstool_use, regardless ofstop_reason- Same fix applied to
PlanExecuteLoopandReflectionLoop - Added regression test
testToolUseWithMaxTokensStopReasonStillAddsToolResults
Upgrade
composer update claude-php/agentNo breaking changes. Drop-in replacement for v1.4.5.