-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: add tool/function calling support to Anthropic Messages API #7956
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add tool/function calling support to Anthropic Messages API #7956
Conversation
✅ Deploy Preview for localai ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Co-authored-by: mudler <2420543+mudler@users.noreply.github.com>
Co-authored-by: mudler <2420543+mudler@users.noreply.github.com>
| Expect(message.Content).ToNot(BeEmpty()) | ||
|
|
||
| // Check if there's a tool use in the response | ||
| hasToolUse := false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot in this test we have to assume that we the model will have to call the tools or this should be recorded as a failure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the tests to require tool usage. The first test now asserts Expect(hasToolUse).To(BeTrue()) with a clear error message, and the third test expects toolUseID to be non-empty. Both tests will now fail if the model doesn't call the expected tools. (29de7ec)
| Expect(message.Content).ToNot(BeEmpty()) | ||
| }) | ||
|
|
||
| It("handles tool results in messages", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot let's add also a test for tool call with streaming responses
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comprehensive test for tool calling with streaming responses. The test verifies that:
- Streaming events are properly emitted (content_block_start, content_block_delta, content_block_stop)
- Tool use blocks are correctly accumulated from the stream
- The model calls the tool and stop_reason is set to tool_use
(2b9ab03)
- First test now expects hasToolUse to be true with clear error message - Third test now expects toolUseID to be non-empty (removed conditional) - Both tests will now fail if model doesn't call the expected tools Co-authored-by: mudler <2420543+mudler@users.noreply.github.com>
- Tests that streaming events are properly emitted (content_block_start/delta/stop) - Verifies tool_use blocks are accumulated correctly in streaming mode - Ensures model calls tools and stop_reason is set to tool_use Co-authored-by: mudler <2420543+mudler@users.noreply.github.com>
Summary: Tool/Function Calling Support for Anthropic Messages API ✅
Successfully implemented comprehensive tool/function calling support for the Anthropic Messages API endpoint (
/v1/messages), bringing it to feature parity with the OpenAI chat completions endpoint.Completed Tasks
Schema Updates (core/schema/anthropic.go)
Endpoint Implementation (core/http/endpoints/anthropic/messages.go)
Streaming Support
Testing
Test Coverage
The implementation includes comprehensive E2E tests that validate:
All tests require the model to actually call the provided tools and will fail if tools are not used as expected.
Key Features
✅ Tool Definitions: Full support for Anthropic's tool schema with name, description, and input_schema
✅ Tool Choice Options:
"auto"- model decides"any"- force tool use{"type": "tool", "name": "..."}- force specific tool✅ Tool Use: Returns tool_use content blocks with ID, name, and parsed input
✅ Tool Results: Handles tool_result blocks in messages for multi-turn tool interactions
✅ Streaming: Incremental tool call detection and proper event emission
✅ Compatibility: Uses same internal functions as OpenAI endpoint for consistency
Implementation Quality
The implementation is production-ready and fully compatible with the Anthropic Messages API specification.
Original prompt
This pull request was created from Copilot chat.
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.