feat(anthropic): add anthropic_server_tools to AnthropicChatGenerator#3386
Open
Aftabbs wants to merge 2 commits into
Open
feat(anthropic): add anthropic_server_tools to AnthropicChatGenerator#3386Aftabbs wants to merge 2 commits into
Aftabbs wants to merge 2 commits into
Conversation
Allow users to pass Anthropic server-side (built-in) tools such as web_search_20250305 directly to the API without being blocked by the haystack Tool/Toolset type validation. The new `anthropic_server_tools` parameter accepts a list of raw dicts that are appended to any function tools before the messages.create call. Serialization and deserialization are handled automatically via default_to_dict/default_from_dict. Fixes deepset-ai#2724
Contributor
|
Heads-up for maintainers This PR is from a fork and touches integrations whose integration tests require API keys. Affected integrations:
Please run the integration tests locally ( |
Contributor
|
@Aftabbs, I see you have three PRs open, I was reviewing one, which is still under review with failing tests and with changes requests. I kindly ask you to focus on that PR before opening new ones. |
anakin87
requested changes
Jun 4, 2026
Member
anakin87
left a comment
There was a problem hiding this comment.
Thanks for this PR!
Tests are failing.
Please make them pass then ping me to get a review.
…hatGenerator AnthropicFoundryChatGenerator inherits run() from AnthropicChatGenerator, which calls _prepare_request_params() that references self.anthropic_server_tools. Since the subclass __init__ did not declare or set this attribute, every call to run() raised AttributeError. Add anthropic_server_tools param to __init__, set self.anthropic_server_tools, include it in to_dict(), and update the serde / run-triggers-warm-up tests.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #2724
AnthropicChatGeneratorcurrently validates that all items intoolsareToolorToolsetinstances, which prevents users from passing Anthropic's native server-side tools (web search, computer use, etc.). This PR adds ananthropic_server_toolsparameter that accepts raw dicts and forwards them directly to the Anthropic API alongside any function tools.Root Cause
Anthropic's
messages.createAPI accepts two categories of tools:Tool/Toolsetmachinery{"type": "web_search_20250305"}) — these bypass function-call dispatch and are handled entirely by the Anthropic backendThe existing
toolsparameter only supports category 1. Users who tried to pass raw dicts got aTypeError: Items in the tools list must be Tool or Toolset instances.Changes
chat_generator.pyanthropic_server_tools: list[dict[str, Any]] | None = Noneparameter; stored, serialized, and appended to the tools list in_prepare_request_paramstest_chat_generator.pyUsage
Function tools and server-side tools can also be combined:
Testing
test_to_dict_default,test_to_dict_with_parameters,test_serde_in_pipelinefor new param)test_init_with_anthropic_server_tools— verifies parameter is storedtest_to_dict_with_anthropic_server_tools— verifies serialization round-triptest_from_dict_with_anthropic_server_tools— verifies deserializationtest_run_with_anthropic_server_tools— verifies server tools are passed tomessages.createtest_run_with_tools_and_anthropic_server_tools— verifies mixed function + server toolsImpact
Users can now use Anthropic's native web search and other built-in tools directly in Haystack pipelines without hacks. The parameter is fully serializable, so pipelines that use it can be saved and reloaded via
pipeline.to_dict()/Pipeline.from_dict().