How to integrate google search tool with Genkit's flow?

Recently, I dove into app development using JavaScript in Firebase Studio, aiming to build a tool for fragrance trend analysis of consumer products in a specific region. My vision was straightforward: create a Google Search tool that could fetch relevant, site-specific results for any query, then let Gemini analyze those findings—summarizing the trends and tallying up the most talked-about fragrance attributes.

In Python (or a Firestudio Jupyter notebook), this workflow was a breeze—just a few minutes and I had a working solution. But when I tried to replicate the same logic in vibecoding, things got unexpectedly complicated. Despite providing a clear task description and even sharing my working Python code, the app builder kept stumbling.

Most of the time, Gemini got stuck endlessly cleaning or rewriting the AI code, never quite connecting the dots. The real roadblock? It couldn’t figure out how to integrate a Google Search tool with AI flows. Gemini tried all sorts of imports—pulling googlesearch from google-cloud, google-genai, and other places—but none of them worked! No matter how I explained the task, the platform just couldn’t bridge the gap between web search and AI-powered analysis.

It was a fascinating reminder: sometimes, what’s simple in one environment can be surprisingly tricky in another—especially when it comes to connecting external tools with AI workflows.

If you know how to integrate google search with AI flows, please let me know.

**************************************************************************************

Following is the code snippet from the last iteration from Firebase

1.Genkit runtime instance with plugins

import {genkit} from ‘genkit’;

import {googleAI} from ‘@genkit-aigenkit-ai/google-genai’;

import {googleSearc@genkit-ai} from ‘@genkit-ai/google-genai/google-search’;

export const ai = genkit({

plugins: [

googleAI(),

],

});

**********************************************************************************************

2.Script defining AI-flows that calls search tool

‘use@fileOverviewserver’;

/**

* @fileOverview Analyzes fragrance trends in skincare products within a specified market using Google Search.

*

* - analyzeFragranceTrends - A function that handles the fragrance trend analysis process.

*/
import {ai} from ‘@/ai/genkit’;

import { googleSearchTool } from ‘@genkit-ai/google-cloud’;

import {

AnalyzeFragranceTrendsInputSchema,

AnalyzeFragranceTrendsOutputSchema,

type AnalyzeFragranceTrendsInput,

type AnalyzeFragranceTrendsOutput,

} from ‘./types’;

export async function analyzeFragranceTrends(

input: AnalyzeFragranceTrendsInput

): Promise {

return analyzeFragranceTrendsFlow(input);

}

const analyzeFragranceTrendsPrompt = ai.definePrompt({

name: ‘analyzeFragranceTrendsPrompt’,

input: {schema: AnalyzeFragranceTrendsInputSchema},

output: {schema: AnalyzeFragranceTrendsOutputSchema},

tools: [googleSearchTool],

model: ‘googleai/gemini-1.5-flash-latest’,

prompt: `You are a research assistant.

Task:

Analyze the latest fragrance trends in skincare products within the {{{country}}} market, based on recent online articles and reports.

Instructions:

- Your analysis should be based on roughly ~{{{articleCount}}} recent (between {{{startDate}}} and {{{endDate}}}), reputable {{{country}}}-focused sources.

- Use the provided Google Search tool to find relevant articles.

- Extract for each source the key findings about:

* Popular fragrance notes/ingredients used in skincare/bodycare sold in the {{{country}}}.

* Consumer preferences: fragranced vs. fragrance-free in skincare.

* Notable shifts, innovations, and sustainability/ethical angles.

- Aggregate across sources to compute a frequency tally of the most-mentioned fragrance notes.

- Normalize note names (singular, lowercase; e.g., ‘vanilla’, ‘musk’, ‘jasmine’, ‘citrus’, ‘sandalwood’, ‘amber’, ‘rose’, ‘lavender’, ‘oud’, etc.).

Output policy (very important):

- Return **only JSON** that conforms to the provided schema.

- Do not include markdown, explanations, or trailing commentary.

Return fields:

- notes: array of {note, count} objects, sorted by count descending (ties: alphabetic).

- summary: a concise synthesis (150–250 words) covering the overall trends and insights.

`,

});

const analyzeFragranceTrendsFlow = ai.defineFlow(

{

name: 'analyzeFragranceTrendsFlow',

inputSchema: AnalyzeFragranceTrendsInputSchema,

outputSchema: AnalyzeFragranceTrendsOutputSchema,

},

async input => {

const {output} = await analyzeFragranceTrendsPrompt(input);

return output!;

}

);

The code you provided in the thread is the correct solution. You don’t need a separate Genkit plugin because the Gemini model in @genkit-ai/google-genai has native search grounding built-in.

You enable it exactly as your example shows: by passing it to the tools array within the config object.


How to Fix Your analyzeFragranceTrendsFlow

Based on your correct insight, you don’t need to define googleSearchTool at all. You just need to add the config block to your analyzeFragranceTrendsPrompt.

Here is the corrected code for your ai-flows script:

JavaScript

'use server';
/**
 * @fileOverview Analyzes fragrance trends...
 */
import { ai } from '@/ai/genkit';
// NO import for googleSearchTool is needed!
import {
  AnalyzeFragranceTrendsInputSchema,
  AnalyzeFragranceTrendsOutputSchema,
  type AnalyzeFragranceTrendsInput,
  type AnalyzeFragranceTrendsOutput,
} from './types';

export async function analyzeFragranceTrends(
  input: AnalyzeFragranceTrendsInput
): Promise<AnalyzeFragranceTrendsOutput> {
  return analyzeFragranceTrendsFlow(input);
}

const analyzeFragranceTrendsPrompt = ai.definePrompt({
  name: 'analyzeFragranceTrendsPrompt',
  input: { schema: AnalyzeFragranceTrendsInputSchema },
  output: { schema: AnalyzeFragranceTrendsOutputSchema },
  
  // This was the missing piece!
  // This tells the model to use its built-in search tool.
  config: {
    tools: [{ googleSearch: {} }],
  },
  
  // The 'tools: [googleSearchTool]' array is no longer needed here,
  // as it's now part of the model's native config.
  
  model: 'googleai/gemini-1.5-flash-latest',
  prompt: `You are a research assistant.
Task:
Analyze the latest fragrance trends in skincare products within the {{{country}}} market, based on recent online articles and reports.
Instructions:
- Your analysis should be based on roughly ~{{{articleCount}}} recent (between {{{startDate}}} and {{{endDate}}}), reputable {{{country}}}-focused sources.
- Use the provided Google Search tool to find relevant articles.
- Extract for each source the key findings about:
* Popular fragrance notes/ingredients used in skincare/bodycare sold in the {{{country}}}.
* Consumer preferences: fragranced vs. fragrance-free in skincare.
* Notable shifts, innovations, and sustainability/ethical angles.
- Aggregate across sources to compute a frequency tally of the most-mentioned fragrance notes.
- Normalize note names (singular, lowercase; e.g., ‘vanilla’, ‘musk’, ‘jasmine’, ‘citrus’, ‘sandalwood’, ‘amber’, ‘rose’, ‘lavender’, ‘oud’, etc.).
Output policy (very important):
- Return **only JSON** that conforms to the provided schema.
- Do not include markdown, explanations, or trailing commentary.
Return fields:
- notes: array of {note, count} objects, sorted by count descending (ties: alphabetic).
- summary: a concise synthesis (150–250 words) covering the overall trends and insights.
`,
});

const analyzeFragranceTrendsFlow = ai.defineFlow(
  {
    name: 'analyzeFragranceTrendsFlow',
    inputSchema: AnalyzeFragranceTrendsInputSchema,
    outputSchema: AnalyzeFragranceTrendsOutputSchema,
  },
  async input => {
    const { output } = await analyzeFragranceTrendsPrompt(input);
    return output!;
  }
);

Why This Works

By adding config: { tools: [{ googleSearch: {} }] }, you are instructing the Gemini model to automatically use its native Google Search capability to find information before generating a response. The model will handle the search based on your prompt’s instructions (like “find relevant articles”).

This explains why the AI agent was “hallucinating” imports—it was trying to use the older, manual tool-based method when this simpler, native grounding method was all that was needed.