Prompt Chain

Automate Google AI Studio Tasks

Promptfoo example covering Google AI Studio function calling, search grounding, code execution, and URL context with Gemini models.

Works with google ai studiopromptfoo

92
Spark score
out of 100
Updated last month
Version code-scan-action-0.1
Models

Add to Favorites

Why it matters

Leverage Google AI Studio's advanced features like function calling, search, and code execution through promptfoo. Streamline complex AI interactions and automate multi-step processes.

Outcomes

What it gets done

01

Integrate Google AI Studio capabilities into automated workflows.

02

Utilize function calling for structured AI responses.

03

Execute code and leverage search within AI Studio.

04

Process URL context for enhanced AI understanding.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-google-aistudio-tools | bash

Steps

Steps in the chain

01
Function Calling
02
Google Search Integration
03
Code Execution
04
URL Context

Overview

Google Aistudio Tools

This promptfoo example validates four Gemini tool-use capabilities - function calling, Google Search grounding, code execution, and URL context - each with a dedicated config. Use it when building Gemini-based function calling, search-grounded answers, code execution, or URL-content analysis and you need a working starting config for each capability.

What it does

This promptfoo example demonstrates four Google AI Studio capabilities through Gemini models: function calling (invoking predefined functions from user queries), Google Search grounding (pulling real-time web information into responses), Python code execution (solving computational problems), and URL context (extracting and analyzing content from web pages) - each with its own ready-to-run config file.

When to use - and when NOT to

Use it when you're building with Gemini's tool-use features and need working reference configs - validating that a model produces correctly-structured function calls, grounding responses in current web information via Google Search, executing code to answer computational questions, or pulling in URL content for analysis. Do not use it if you only need plain text generation with no tool use, since each of the four configs is scoped to a specific tool-calling capability rather than general chat.

Inputs and outputs

Requires a GOOGLE_API_KEY environment variable. The function-calling config defines a weather function in tools.json and validates that Gemini produces a structured call whose location parameter matches the user's query. The search config runs queries against three model/config combinations - Gemini 2.5 Flash with search, Gemini 2.5 Pro with thinking plus search, and Gemini 2.5 Flash-Lite with search - and verifies the response includes relevant, current information. The code-execution config tests computational problems and checks the code-derived answer is correct. The URL-context config extracts and analyzes content from web URLs, optionally combined with search.

Integrations

Runs via npx promptfoo@latest init --example google-aistudio-tools, then promptfoo eval -c pointed at whichever config you need: promptfooconfig.yaml (function calling), promptfooconfig.search.yaml (search grounding), promptfooconfig.codeexecution.yaml (code execution), or promptfooconfig.urlcontext.yaml (URL context). Search grounding is enabled with tools: [{googleSearch: {}}] in the provider config, optionally combined with generationConfig: {thinkingConfig: {thinkingBudget: 1024}} for reasoning-assisted search. Google requires displaying "Google Search Suggestions" in any user-facing app that uses this grounding, and the API response includes search metadata and sources alongside the answer.

Three search approaches are demonstrated. Search as a tool lets the model decide when to search:

tools:
  - googleSearch: {}

Search with thinking adds reasoning capability on top:

generationConfig:
  thinkingConfig:
    thinkingBudget: 1024
tools:
  - googleSearch: {}

And search on Flash-Lite uses the same tool with the lower-cost model for cheaper grounded queries.

Who it's for

Developers building Gemini-based function calling, search-grounded answers, code-execution workflows, or URL-content analysis who want a validated starting config for each capability instead of assembling one from documentation alone. The example ships all four configs plus tools.json together, so each capability can be tried in isolation before being combined into a larger Gemini application.

Source README

google-aistudio-tools (Google AI Studio Tools)

This example demonstrates how to use Google AI Studio's function calling, search capabilities, code execution, and URL context features with promptfoo.

You can run this example with:

npx promptfoo@latest init --example google-aistudio-tools
cd google-aistudio-tools

Prerequisites

  • Google AI Studio API key set as GOOGLE_API_KEY in your environment

Overview

This example shows how to:

  1. Function Calling: Use Gemini to invoke predefined functions based on user queries
  2. Google Search Integration: Get up-to-date information from the web using Gemini models with search grounding
  3. Code Execution: Execute Python code to solve computational problems
  4. URL Context: Extract and analyze content from web URLs

Function Calling Example

The function calling configuration (promptfooconfig.yaml) demonstrates:

  • Defining a weather function in tools.json
  • Validating that Gemini models correctly produce structured function calls
  • Testing that the location parameter matches the user's query

Run with:

promptfoo eval -c promptfooconfig.yaml

Search Grounding Example

The search grounding configuration (promptfooconfig.search.yaml) demonstrates:

  • Using Gemini 2.5 Flash with Google Search as a tool
  • Using Gemini 2.5 Pro with thinking capabilities and Search grounding
  • Using Gemini 2.5 Flash-Lite with Google Search grounding
  • Testing queries that benefit from real-time web information
  • Verifying responses include relevant information

Run with:

promptfoo eval -c promptfooconfig.search.yaml

Code Execution Example

The code execution configuration (promptfooconfig.codeexecution.yaml) demonstrates:

  • Testing computational problems that require code to solve
  • Verifying that the answer is correct from the code execution

Run with:

promptfoo eval -c promptfooconfig.codeexecution.yaml

URL Context Example

The URL context configuration (promptfooconfig.urlcontext.yaml) demonstrates:

  • Using Gemini to extract and analyze content from web URLs
  • Combining URL context with search capabilities

Run with:

promptfoo eval -c promptfooconfig.urlcontext.yaml

Example Files

  • promptfooconfig.yaml: Function calling configuration
  • promptfooconfig.search.yaml: Search grounding configuration
  • promptfooconfig.codeexecution.yaml: Code execution configuration
  • promptfooconfig.urlcontext.yaml: URL context configuration
  • tools.json: Function definition for the weather example

Notes on Google Search Integration

When using Search grounding in your own applications:

  • The API response includes search metadata and sources
  • Google requires displaying "Google Search Suggestions" in user-facing apps
  • Models can retrieve current information about events, prices, and technical updates

Search Methods

This example demonstrates three approaches to search:

  1. Search as a tool (Gemini 2.5): Allows the model to decide when to use search

    tools:
      - googleSearch: {}
    
  2. Search with thinking (Gemini 2.5): Adds thinking capabilities for better reasoning

    generationConfig:
      thinkingConfig:
        thinkingBudget: 1024
    tools:
      - googleSearch: {}
    
  3. Search on Flash-Lite (Gemini 2.5): Uses the lower-cost Flash-Lite model with the same search tool

    tools:
      - googleSearch: {}
    

Further Resources

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.