Skip to content

v1.4.6

Choose a tag to compare

@dalehurley dalehurley released this 06 Feb 03:25
· 4 commits to master since this release

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 to ToolExecutionTrait that inspects response content directly
  • ReactLoop now always adds tool_result blocks when content contains tool_use, regardless of stop_reason
  • Same fix applied to PlanExecuteLoop and ReflectionLoop
  • Added regression test testToolUseWithMaxTokensStopReasonStillAddsToolResults

Upgrade

composer update claude-php/agent

No breaking changes. Drop-in replacement for v1.4.5.