Flag failed tool results as errors when sending them to Anthropic

Merged
SU
3d ago
+52-1

when a tool throws the loop marks its ToolResult as failed and sends The tool call failed: <message> back but the Anthropic gateway maps it like any successful result
Anthropic documents is_error: true on tool_result for exactly this case (tool execution errors and invalid tool calls) so this adds it when $toolResult->failed is set
successful results go out exactly like before

failed is persisted since #812 so a failed result replayed from a stored conversation gets the flag too and the replayed history matches what the earlier turn sent

checked live with a tool that throws once and then works
on claude-sonnet-5-5 the request after the failure carries is_error: true in both prompt() and stream() and the API took it
same on claude-fable-5-2
in a stored conversation the second turn replays the failed result with is_error: true and read the first turn's 8921 cached tokens so the prefix didn't change

https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls#handling-errors-with-is_error