diff --git a/src/ValueObjects/ToolCall.php b/src/ValueObjects/ToolCall.php index 7329979ed..2da29fa39 100644 --- a/src/ValueObjects/ToolCall.php +++ b/src/ValueObjects/ToolCall.php @@ -34,10 +34,13 @@ public function arguments(): array return []; } - $arguments = $this->arguments; + // Sanitize control characters that some providers (e.g. DeepSeek) may include + // in streamed tool call arguments. Raw 0x00-0x1F / 0x7F bytes are never valid + // in JSON (RFC 8259) and cause json_decode to throw "Control character error". + $arguments = preg_replace('/[\x00-\x1F\x7F]/', '', $this->arguments); return json_decode( - $arguments, + (string) $arguments, true, flags: JSON_THROW_ON_ERROR );