Add streamed tool calls for Anthropic and expand Mistral tool support#151
Conversation
Anthropic streaming now assembles tool invocations from the "tool_use" start block and the following "input_json_delta" fragments, decoding the concatenated JSON once the stream signals stop_reason "tool_use". Malformed or truncated argument JSON fails fast instead of being silently dropped. Mistral tool support is expanded beyond the large model to small, medium, nemo and pixtral-large, which all support function calling.
|
Warning Review limit reached
More reviews will be available in 47 minutes and 51 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (24)
📒 Files selected for processing (2)
WalkthroughThis PR implements streamed tool-call handling for the Anthropic adapter and expands tool support in the Mistral adapter. The Anthropic changes extend response types to carry tool metadata, rework the streaming loop to accumulate and synthesize tool messages, and validate the flow end-to-end. The Mistral changes broaden tool support from one model to five. ChangesAnthropic Streamed Tool Support
Mistral Tool Support Broadening
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
packages/mistral/tests/Unit/Resources/ChatTest.php (2)
314-324: ⚡ Quick winConsider renaming test method to reflect actual intent.
Now that multiple models support tools, the name
testCreateStreamedWithToolsForNoneLargeis misleading. The test validates rejection of tool calls for unsupported models. Additionally, "NoneLarge" appears to be a typo.Suggested rename:
testCreateStreamedWithToolsForUnsupportedModel📝 Proposed rename
- public function testCreateStreamedWithToolsForNoneLarge(): void + public function testCreateStreamedWithToolsForUnsupportedModel(): void🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/mistral/tests/Unit/Resources/ChatTest.php` around lines 314 - 324, Rename the PHPUnit test method testCreateStreamedWithToolsForNoneLarge to a name that reflects its intent; update the method declaration in class ChatTest from testCreateStreamedWithToolsForNoneLarge to testCreateStreamedWithToolsForUnsupportedModel so it clearly indicates the test verifies rejection of tool calls for unsupported models (keep the body, assertions and references to createStreamed, DataFixtures::CHAT_CREATE_REQUEST_WITH_TOOLS, and Model::TINY unchanged).
158-170: ⚡ Quick winConsider renaming test method to reflect actual intent.
Now that multiple models (SMALL, MEDIUM, LARGE, NEMO, PIXTRAL_LARGE) support tools, the name
testCreateWithToolsForNonLargeModelis misleading. The test validates rejection of tool calls for unsupported models, not "non-large" models specifically.Suggested rename:
testCreateWithToolsForUnsupportedModel📝 Proposed rename
- public function testCreateWithToolsForNonLargeModel(): void + public function testCreateWithToolsForUnsupportedModel(): void🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/mistral/tests/Unit/Resources/ChatTest.php` around lines 158 - 170, Rename the test method to reflect that it asserts rejection for models that do not support tools: change the method name testCreateWithToolsForNonLargeModel to testCreateWithToolsForUnsupportedModel inside the ChatTest class; update any references or usages (e.g., the test method definition itself and any test suite metadata) so the method still executes, keeping the body that sets $requestData = DataFixtures::CHAT_CREATE_REQUEST_WITH_TOOLS and $requestData['model'] = Model::TINY->value and the assertions around $this->expectException(\InvalidArgumentException::class) and $chat->create($requestData).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@packages/mistral/tests/Unit/Resources/ChatTest.php`:
- Around line 314-324: Rename the PHPUnit test method
testCreateStreamedWithToolsForNoneLarge to a name that reflects its intent;
update the method declaration in class ChatTest from
testCreateStreamedWithToolsForNoneLarge to
testCreateStreamedWithToolsForUnsupportedModel so it clearly indicates the test
verifies rejection of tool calls for unsupported models (keep the body,
assertions and references to createStreamed,
DataFixtures::CHAT_CREATE_REQUEST_WITH_TOOLS, and Model::TINY unchanged).
- Around line 158-170: Rename the test method to reflect that it asserts
rejection for models that do not support tools: change the method name
testCreateWithToolsForNonLargeModel to testCreateWithToolsForUnsupportedModel
inside the ChatTest class; update any references or usages (e.g., the test
method definition itself and any test suite metadata) so the method still
executes, keeping the body that sets $requestData =
DataFixtures::CHAT_CREATE_REQUEST_WITH_TOOLS and $requestData['model'] =
Model::TINY->value and the assertions around
$this->expectException(\InvalidArgumentException::class) and
$chat->create($requestData).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7dd94684-26e8-42fa-afaa-168aecaa6a30
📒 Files selected for processing (9)
packages/anthropic-adapter/phpstan-baseline.neonpackages/anthropic-adapter/src/Chat/AnthropicChatAdapter.phppackages/anthropic-adapter/tests/Unit/Chat/AnthropicChatAdapterTest.phppackages/anthropic/src/DataFixtures.phppackages/anthropic/src/Responses/Messages/CreateStreamedResponse.phppackages/anthropic/src/Responses/Messages/CreateStreamedResponseDelta.phppackages/anthropic/tests/Unit/Resources/MessagesTest.phppackages/mistral/src/Model.phppackages/mistral/tests/Unit/Resources/ChatTest.php
The tests now reject tool calls for Model::TINY, so name them ForUnsupportedModel instead of the outdated ForNonLarge/ForNoneLarge.
Summary
AnthropicChatAdapternow assembles tool invocations from the streamedtool_usestart block (id + name) and the followinginput_json_deltafragments, decoding the concatenated JSON once the stream signalsstop_reason: "tool_use". Previously tool calls were only supported on non-streamed responses.JSON_THROW_ON_ERROR) instead of silently producing an empty-argument tool call. A genuine no-argument call still resolves to[].CreateStreamedResponseDelta/CreateStreamedResponsecarry the new tool-call fields (id,name,input,partial_json) and only requireindex+type.Model::toolsSupported()now coverssmall,medium,large,nemoandpixtral-large(was large-only), reflecting the models that actually support function calling.Tests
testHandleRequestStreamedWithTools(anthropic-adapter) covering the full streamed tool-call flow.testCreateStreamedWithTools(anthropic) verifying parsing oftool_useandinput_json_deltadeltas.tiny(still unsupported) now thatmediumsupports tools.Validation
✅ PHPUnit, ✅ PHPStan, ✅ PHP-CS-Fixer / Rector — all green across the
anthropic,anthropic-adapterandmistralpackages.Summary by CodeRabbit
New Features
Tests