feat(google_genai): add google_server_tools to GoogleGenAIChatGenerator#3571
feat(google_genai): add google_server_tools to GoogleGenAIChatGenerator#3571Aftabbs wants to merge 2 commits into
Conversation
…hatGenerator Adds `google_server_tools: list[dict[str, Any]] | None = None` to `GoogleGenAIChatGenerator.__init__`, enabling users to pass Google's built-in server-side tools (e.g. google_search, code_execution) directly to the Gemini API. These tools are merged with any Haystack Tool/Toolset at request time: each dict is converted to a `google.genai.types.Tool` via model_validate and appended to the tools list sent in `GenerateContentConfig`. Follows the same pattern as `anthropic_server_tools` in deepset-ai#3386. Closes #<TBD>
|
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 ( |
Coverage report (google_genai)Click to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
| :param streaming_callback: A callback function that is called when a new token is received from the stream. | ||
| :param tools: A list of Tool and/or Toolset objects, or a single Toolset for which the model can prepare calls. | ||
| Each tool should have a unique name. | ||
| :param google_server_tools: A list of Google server-side (built-in) tools passed directly to the API. |
There was a problem hiding this comment.
Could you explain how this syntax works?
We should support all Google built-in tools if possible, also allowing to pass potential parameters they accept.
So let's verify that this syntax is functional for this goal or choose another one; also provide users with an example in docstring and a link to Google tools.
| assert restored._generation_kwargs["response_format"] == schema | ||
| assert restored._generation_kwargs["temperature"] == 0.5 | ||
|
|
||
| def test_init_with_google_server_tools(self, monkeypatch): |
There was a problem hiding this comment.
Let's incorporate these new tests into existing tests or at least move them close to other similar ones
| # _convert_tools_to_google_genai_format bundles all function declarations into one Tool object, | ||
| # plus one Tool object for google_search | ||
| assert len(config.tools) == 2 | ||
|
|
There was a problem hiding this comment.
Let's add a live integration test in the appropriate section.
…ests - Expand google_server_tools docstring: explain dict-to-Tool conversion, list all built-in tools (google_search, code_execution, url_context), add usage example and link to Google built-in tools docs - Move serde tests (test_init/to_dict/from_dict_with_google_server_tools) adjacent to mixed-toolset tests in TestGoogleGenAIChatGeneratorInitSerDe - Add live integration test test_live_run_with_google_server_tools to TestGoogleGenAIChatGeneratorInference
|
Yes — I tested the parameter wiring and serialization locally (unit tests pass). For the live API path, I've added |
Summary
google_server_tools: list[dict[str, Any]] | None = Noneparameter toGoogleGenAIChatGenerator.__init__google_search,code_execution) to the Gemini APITool/Toolsetat request time and passed inGenerateContentConfig.toolsto_dict()/from_dict()Motivation
Google's Gemini API supports built-in tools that are not Haystack
Toolobjects and cannot be expressed as function declarations. For example:Currently there is no way to pass these through
GoogleGenAIChatGeneratorbecause thetoolsparameter only acceptsToolsType(Haystack Tools/Toolsets). This PR addsgoogle_server_toolsto fill that gap.Usage:
Or combined with Haystack tools:
Relation to existing work
Follows the same pattern as
anthropic_server_toolsintroduced in #3386 forAnthropicChatGenerator.Test plan
test_init_with_google_server_tools— verifies_google_server_toolsis stored on inittest_to_dict_with_google_server_tools— verifies serialization round-triptest_from_dict_with_google_server_tools— verifies deserialization round-triptest_to_dict_default_google_server_tools_is_none— verifies default isNonetest_run_with_google_server_tools— verifies native tool is passed toGenerateContentConfigtest_run_merges_haystack_and_google_server_tools— verifies Haystack + native tools are merged