Function Calling & Tools
Function Calling & Tools on Google Cloud is the pattern of letting Gemini or agent runtimes emit structured tool calls, execute those calls in application or managed infrastructure, and return tool results back to the model for final reasoning. It spans direct Gemini function calling, code execution, Computer Use, MCP/A2A tools, Agent Engine deployments, managed agents, and evaluation of tool trajectories.
Synthesized across 73 notebooks. See the source pages under Notebooks below for line-level grounding.
At the model layer, engineers define tools with explicit names, descriptions, JSON schemas, required fields, and tool configuration modes such as AUTO, ANY, and NONE. The model predicts structured function calls; application code remains responsible for validating arguments, executing external systems, and returning function responses before asking for the final answer.
At the agent layer, Vertex AI Agent Engine, ADK, LangChain, LangGraph, A2A, MCP, Cloud API Registry, and Managed Agents provide deployment, sessions, streaming, memory, tracing, sandboxed code execution, and remote tool access. Most notebooks emphasize testing tools and agents locally, packaging deployment artifacts carefully, using Cloud Storage staging buckets, and cleaning up billable resources.
For production-grade workflows, tool use should be observable and evaluated: stream intermediate events, inspect state and traces, persist session history when needed, and use Vertex AI Gen AI Evaluation Service or custom metrics to check tool selection, parameter quality, trajectory order, and final response quality.
Canonical workflow
- Choose the tool surface: direct Gemini function calling, code execution, Computer Use, ADK/LangChain/LangGraph agent, MCP/A2A tool, Cloud API Registry tool, or Managed Agents API.
- Define tools explicitly with clear names, descriptions, typed schemas, required fields, and safe constraints on what external systems may do.
- Test each tool function directly, then test the model or agent locally with deterministic settings such as temperature 0 when predictable tool behavior matters.
- Execute model-requested tool calls in application code or a managed executor, validate arguments and outputs, and return function_response or tool_result messages to the model.
- Add session, memory, artifacts, streaming, tracing, and human-in-the-loop checkpoints when the workflow needs continuity, auditability, or oversight.
- Package and deploy with explicit requirements, entry points, environment variables, service accounts, IAM roles, staging buckets, and region settings.
- Poll asynchronous operations such as agent creation, deployment, task execution, or evaluation runs until completion before reading outputs.
- Evaluate and monitor tool behavior with traces, intermediate events, reference trajectories, custom metrics, and cleanup of deployed or billable resources.
Best practices
See Function Calling & Tools - Best Practices for the full distilled guide.
- Use function declarations and schemas to constrain tool arguments instead of parsing freeform text or generating arbitrary SQL.
- Give every tool a specific name, description, parameter type, property description, and required-field list where appropriate.
- Set temperature to 0 for deterministic function-calling, guardrail, code execution, and tool-review examples when repeatability matters.
- Always execute tools in application code or a managed executor, then append the tool results back to the model before requesting the final answer.
- Handle multiple or parallel function calls by executing independent calls concurrently when safe and returning all function responses in bulk.
- Validate tool-call names and arguments before execution, and validate returned rows or payloads with structured models such as Pydantic where used.
Key models & APIs
- gemini-2.5-flash, gemini-3.5-flash, gemini-2.5-flash-lite, gemini-2.0-flash, gemini-2.5-computer-use-preview-10-2025, claude-sonnet-4@20250514, vertex_ai/claude-sonnet-4-5@20250929, vertex_ai/meta/llama-3.3-70b-instruct-maas, antigravity-preview-05-2026, Google Gen AI SDK google-genai, Vertex AI API, Vertex AI Agent Engine, Agent Platform Managed Agents API, Agent Development Kit ADK, A2A SDK and Agent Cards, MCP and MCPToolset, Cloud API Registry and API Hub, Agent Engine Sandbox Code Executor, BuiltInCodeExecutor, OpenAI Chat Completions compatibility on Vertex AI, LangChain and LangGraph, Vertex AI Session Service, Vertex AI Gen AI Evaluation Service and EvalTask, Cloud Trace, Phoenix, and OpenInference tracing, BigQuery, Vertex AI Search, Google Maps APIs, Cloud SQL, Cloud Run, Cloud Storage, Secret Manager
Notebooks (73)
Agents & ADK (11)
- Get started with A2A on Agent Engine — Builds, deploys, and queries an A2A Q&A agent on Vertex AI Agent Engine.
- Claude with ADK on Vertex AI Agent Engine — Builds and deploys a Claude-powered ADK Reddit agent on Vertex AI Agent Engine with memory and tracing.
- Deploy your first agent to Vertex AI Agent Engine — Deploys ADK agents to Vertex AI Agent Engine with Express Mode, agent object, and inline source workflows.
- Get started with Agent Engine Terraform Deployment — Deploy Vertex AI Agent Engine agents with Terraform, cloudpickle packaging, and ADK tools.
- Get started with Cloud API Registry on Vertex AI Agent Engine — Builds and deploys an ADK BigQuery data analyst agent using Cloud API Registry on Vertex AI Agent Engine.
- Get started with Code Execution on Vertex AI Agent Engine — Runs LLM-generated Python securely with Vertex AI Agent Engine Sandbox and ADK agents.
- MCP on Vertex AI Agent Engine with custom installation scripts — Deploys a Reddit MCP tool agent to Vertex AI Agent Engine with custom install scripts.
- Building multi-agent systems with Vertex AI and Claude — Builds a Vertex AI Agent Engine multi-agent market analysis system with Gemini, Claude, ADK, A2A, and MCP.
- Building Multi-Agent Systems with Vertex AI and Llama model — Builds a traced Vertex AI multi-agent trading analyst with Gemini, Llama, ADK, A2A, and MCP tools.
- Intro to Managed Agents API on Agent Platform (cURL) — Shows how to manage and interact with Managed Agents on Agent Platform using REST and cURL.
- Intro to Managed Agents API on Agent Platform (Python) — Shows how to create, inspect, interact with, and delete Managed Agents with google-genai.
Gemini (56)
- Vertex AI Agent Engine in Express Mode — Build, test, deploy, and query a Gemini ADK currency agent on Vertex AI Agent Engine Express Mode.
- Intro to Building and Deploying an Agent with Agent Engine in Vertex AI — Builds, tests, deploys, streams, customizes, and deletes a LangChain Gemini agent on Vertex AI Agent Engine.
- Persisting LangChain History with Vertex AI Session Service — Persists LangChain chat and tool history in Vertex AI Agent Engine Session Service.
- Building and Deploying a Human-in-the-Loop LangGraph Application with Agent Engine on Vertex AI — Builds, tests, deploys, and resumes a human-in-the-loop LangGraph agent on Vertex AI Agent Engine.
- Debugging and Optimizing Agents: A Guide to Tracing in Agent Engine — Builds, deploys, and traces a Gemini LangChain agent on Vertex AI Agent Engine.
- Building and Deploying a Google Maps API Agent with Agent Engine — Builds, tests, deploys, and queries a Gemini Google Maps agent on Vertex AI Agent Engine.
- Building and Deploying a LangGraph Agent with Agent Engine in Vertex AI — Builds, tests, deploys, and deletes a Gemini LangGraph agent on Vertex AI Agent Engine.
- Deploying an Agent with Agent Engine and MCP Toolbox for Databases — Deploys a Gemini hotel-booking agent on Agent Engine using Cloud SQL, Cloud Run Toolbox, and LangGraph.
- Building a Conversational Search Agent with Agent Engine and RAG on Vertex AI Search — Builds and deploys a Gemini movie-search RAG agent with LangChain, Agent Engine, and Vertex AI Search.
- Function Calling Agent — Builds a Gemini function-calling retail assistant over Cymbal Retail data in BigQuery.
- Guardrail Classifier Agent — Builds a LangGraph guardrail classifier agent for Cymbal retail chat using Gemini on Vertex AI.
- Task Planner Agent — Builds a LangGraph task-planner agent that plans, searches with Gemini, reflects, and responds.
- Query a Remote LangGraph Agent Server — Queries a local or Cloud Run LangGraph RemoteGraph agent and displays streamed agent outputs and state.
- Using OpenAI libraries with Gemini on Vertex AI — Calls Gemini on Vertex AI through OpenAI Chat Completions with streaming, tools, schemas, caching, and safety.
- Intro to Gemini Agentic Vision — Uses Gemini code execution for agentic vision tasks: zooming, plotting, and image annotation.
- Intro to Generating and Executing Python Code with Gemini 3 — Uses Gemini 3.5 Flash code execution to generate, run, inspect, and stream Python results via Vertex AI.
- Intro to Computer Use with Gemini — Builds a Gemini Computer Use browser agent loop with Playwright and screenshots.
- Create a Gen AI Agent Evaluation for a Deployed Agent — Runs inference and creates a persisted Gen AI Agent Evaluation for a deployed Vertex AI agent.
- Evaluate Generative Model Tool Use — Evaluates Gemini function calling and saved tool-call predictions with Vertex AI EvalTask metrics.
- Evaluating Agents - Evaluate a CrewAI agent with Vertex AI Gen AI Evaluation Service — Evaluates a CrewAI product agent with Vertex AI Gen AI Evaluation metrics and BYOD evaluation data.
- Evaluating Agents - Evaluate a LangGraph agent with Vertex AI Gen AI Evaluation Service — Evaluates a LangGraph Gemini agent with Vertex AI Gen AI Evaluation metrics and BYOD data.
- Evaluate Generative Model Tool Use with Custom Code Execution — Evaluates Gemini tool-use outputs with Vertex AI remote custom metrics.
- Evaluate your ADK agent using Vertex AI Gen AI Evaluation service — Evaluates an ADK product research agent with Vertex AI Gen AI Evaluation metrics.
- Forced Function Calling with Tool Configurations in Gemini — Shows how to force, allow, or disable Gemini function calls with tool configurations.
- Working with Data Structures and Schemas in Gemini Function Calling — Shows how to extract structured function-call arguments from Gemini using simple, array, and nested schemas.
- Intro to Function Calling with the Gemini API & Python SDK — Introduces Gemini function calling in Vertex AI with chat tools, mock API responses, and live geocoding.
- Multimodal Function Calling with the Gemini API & Python SDK — Shows Gemini multimodal function calling with images, video, audio, PDFs, and chat using Google Gen AI SDK.
- Working with Parallel Function Calls and Multiple Function Responses in Gemini — Shows how Gemini returns and handles parallel function calls with Wikipedia lookup tools.
- Intro to Gemini 2.5 Flash — Introduces Gemini 2.5 Flash on Vertex AI with text, thinking, multimodal, tools, and structured output.
- Intro to Gemini 2.5 Flash-Lite — Introduces Gemini 2.5 Flash-Lite on Vertex AI with prompting, thinking, structured output, search, and code tools.
- Intro to Gemini 2.5 Pro — Introduces Gemini 2.5 Pro on Vertex AI using the Google Gen AI SDK for text, multimodal, tools, and reasoning.
- Intro to Gemini 3.1 Flash-Lite — Quickstart for Gemini 3.1 Flash-Lite with Google Gen AI SDK on Google Cloud.
- Intro to Gemini 3.1 Pro — Quickstart for Gemini 3.1 Pro on Vertex AI with Google Gen AI SDK API features.
- Intro to Gemini 3.5 Flash — Quickstart for Gemini 3.5 Flash generation, multimodal inputs, tools, grounding, and safety with Google GenAI SDK.
- Intro to Gemini 3 Flash (Preview) — Quickstart for Gemini 3 Flash Preview on Vertex AI with Gen AI SDK features and multimodal/tool examples.
- REST API — Uses cURL to call Gemini 3.5 Flash on Vertex AI for text, chat, tools, multimodal, and JSON output.
- Getting started with Gemini using Vertex AI in Express Mode — Introduces Gemini on Vertex AI Express Mode using the Google Gen AI SDK.
- Intro to Model Context Protocol (MCP) integration with Vertex AI — Shows how to connect Gemini on Vertex AI to custom and prebuilt MCP servers.
- Getting Started with Model Optimizer — Introduces Vertex AI Model Optimizer routing with Google Gen AI SDK prompts and function calls.
- Getting Started with Gemini Live API using WebSocket — Uses Gemini Live API over WebSocket for text, audio, video, tools, and native audio features.
- Getting Started with Gemini Live API using Gen AI SDK — Introduces Gemini Live API audio sessions, tools, transcription, and VAD with the Google Gen AI SDK.
- From API to Report: Building a Currency Analysis Agent with LangGraph and Gemini — Builds a LangGraph currency analysis agent using Gemini on Vertex AI and an exchange-rate API.
- Build Your Own AI Podcasting Agent with LangGraph, Gemini, and Chirp 3 — Builds a LangGraph podcast agent using Gemini research loops and Chirp 3 text-to-speech audio.
- Chain of Thought & ReAct — Demonstrates CoT prompting and ReAct agents with Vertex AI, LangChain, Wikipedia, and BigQuery.
- Get Started with Vertex AI Prompt Optimizer - Tool usage — Optimizes a Gemini tool-calling system instruction with Vertex AI Prompt Optimizer data-driven mode.
- Gen AI and LLM Security - ReAct and RAG attacks & mitigations — Demonstrates ReAct and RAG prompt-injection attacks with Gemini and simple mitigations.
- Building a photo recognition agent: Agent Engine setup — Sets up and deploys a Gemini LangChain agent on Agent Engine with Wikipedia and Vertex AI Search tools.
- Intro to thought signatures — Shows how Gemini thought signatures preserve reasoning context across multi-turn function calling.
- Intro to thought signatures with REST API — Shows how to pass Gemini thought signatures through REST function-calling turns.
- Intro to Url Context — Shows how to use Gemini URL context to summarize, compare, and analyze web pages with optional Google Search grounding.
- Analyze a codebase with Gemini in Vertex AI — Uses Gemini 3.5 Flash on Vertex AI to analyze, document, debug, and extend a GitHub codebase.
- Get hands-on with a customer support use case using Gemini and Gen AI SDK — Builds a Gemini customer-support flow for retail product matching, room-fit reasoning, tools, search, and Live API audio.
- ReAct (Reasoning + Acting) + Custom tool for Healthcare NL API + Gemini 2.0 + LangChain — Builds a LangChain ReAct agent using Gemini 2.0 and Healthcare NLP to suggest medical billing codes.
- Productivity Coaching with Gemini and Google Calendar — Uses Gemini 2.5 Flash with Google Calendar data to provide productivity coaching and schedule recommendations.
- Retail AI Location Strategy: Autonomous Site Selection & Market Analysis — Builds a Gemini 3 retail site-selection pipeline using search, Maps, code execution, reasoning, and JSON output.
- Building a Multimodal Chatbot for Warranty Claims using Gemini and Vector Search in Vertex AI — Builds a multimodal warranty-claims chatbot with Gemini, RAG, Vector Search, and function calling.
Open Models (1)
- Serving Open-Source LLMs on Vertex AI with LiteLLM and OpenAI-Compatible APIs — Deploys a Llama 3.1 Model Garden model on Vertex AI and calls it through LiteLLM OpenAI-style APIs.
Partner Models (1)
- Multimodal Function Calling with Claude Models — Uses Claude on Vertex AI for multimodal prompting and tool use with a Wikipedia lookup.
SDK (1)
- Getting started with Google Generative AI using the Gen AI SDK — Introduces Google Gen AI SDK on Vertex AI for Gemini prompts, tools, caching, batches, and embeddings.
Vertex AI Search (2)
- MCP Server with Gemini Enterprise — Builds an MCP HR leave tool on Cloud Run, connects it to an ADK Gemini agent, and registers it with Gemini Enterprise.
- Building Search Applications with Vertex AI Search — Builds Vertex AI Search workflows using Search API, Gemini grounding, and LangChain retrieval.
Workshops (1)
- AI Agents for Engineers (Evolution of AI Agents) — Compares zero-shot, LangChain, and LangGraph essay generation with Gemini and Tavily search.
Related concepts
- Agents & ADK · Gemini Capabilities · Agent Engine · Getting Started · Applied Use Cases · RAG & Grounding · Evaluation · MLOps & Deployment
Part of the Generative AI Google Brain · Function Calling & Tools - Best Practices