ai icon indicating copy to clipboard operation
ai copied to clipboard

v5 @ai-sdk/google custom tools are not available when useSearchGrounding is set to true

Open pavlo-tkhir opened this issue 1 year ago • 5 comments

Description

When GoogleGenerativeAIProviderOptions useSearchGrounding is set to true, the tools defined in the user's code (e.g., in streamText) are overridden by a single googleSearch tool. As a result, the model can't call any other tools.

How to test:

 const result = streamText({
          model: google("gemini-2.5-flash"),
          system: "
                    - Call the generateChatTitle tool to update the title
                    - Reply to the user 
         ",
          messages: convertedMessages,
          providerOptions: {
            google: {
              useSearchGrounding: true,
              thinkingConfig: {
                 thinkingBudget: 12000,
                 includeThoughts: true,
              };
            },
          },
          stopWhen: stepCountIs(5),
          tools: {
            generateChatTitle: tool({
              description: "Generate a concise, descriptive title for the chat session based on the conversation.",
              inputSchema: z.object({
                title: z.string().describe("A concise title (3-6 words) that describes the main topic or purpose of the conversation"),
              }),
              execute: async ({ title }) => {
                // Update the chat session name
                return { success: true, title };
              },
            }),
          },
        });

Most likely because in google-prepare-tools.ts file tools are overridden with a new object:

  if (useSearchGrounding) {
    return {
      tools: isGemini2
        ? { googleSearch: {} }
        : {
            googleSearchRetrieval:
              !supportsDynamicRetrieval || !dynamicRetrievalConfig
                ? {}
                : { dynamicRetrievalConfig },
          },
      toolConfig: undefined,
      toolWarnings,
    };
  }

AI SDK Version

  • "@ai-sdk/google": "^2.0.0-beta.6",
  • "ai": "^5.0.0-beta.4",

pavlo-tkhir avatar Jul 09 '25 15:07 pavlo-tkhir

Image

As i know it is a google limitation, it's the same in the ai studio. As you can see on the picture above if i enable search grounding functions call and structured output is not available. The work around i use is to provide "google search" custom tool with another model which has search grounding enabled and doesn't have other tools. Of course it's worse than using search grounding directly, but model still can fetch actual data.

faradaytrs avatar Jul 10 '25 01:07 faradaytrs

It seems like it has been addressed by google https://ai.google.dev/gemini-api/docs/tool-combination

faradaytrs avatar Mar 19 '26 03:03 faradaytrs

@lgrammel is it possible to address this?

faradaytrs avatar Mar 26 '26 09:03 faradaytrs

Identify issue type

Identified type: Feature
Confidence: Medium

Rationale: Although the original description reports lost custom tools, the comments clarify this behavior was tied to a provider limitation and later became a request for the SDK to support Google's newer tool-combination capability. This is best classified as an enhancement/new capability rather than a confirmed SDK bug.

Evidence:

  • The report says enabling Google provider option useSearchGrounding: true causes user-defined streamText tools to be replaced by a single Google search tool, so the model cannot call generateChatTitle.
  • The reporter points to google-prepare-tools.ts logic that returns only googleSearch/googleSearchRetrieval when useSearchGrounding is enabled.
  • A commenter notes this was a Google limitation at the time, and later comments that Google has since addressed tool combination and asks whether the SDK can address it.

lgrammel avatar Jul 02 '26 09:07 lgrammel

Closing this as superseded. Google Search is now exposed through google.tools.googleSearch(), and models that support tool combinations can use it alongside function tools. The old useSearchGrounding path with Gemini 2.5 remains provider-limited.

gr2m avatar Sep 29 '26 18:09 gr2m