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

  1. 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.
  2. Define tools explicitly with clear names, descriptions, typed schemas, required fields, and safe constraints on what external systems may do.
  3. Test each tool function directly, then test the model or agent locally with deterministic settings such as temperature 0 when predictable tool behavior matters.
  4. 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.
  5. Add session, memory, artifacts, streaming, tracing, and human-in-the-loop checkpoints when the workflow needs continuity, auditability, or oversight.
  6. Package and deploy with explicit requirements, entry points, environment variables, service accounts, IAM roles, staging buckets, and region settings.
  7. Poll asynchronous operations such as agent creation, deployment, task execution, or evaluation runs until completion before reading outputs.
  8. 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)

Gemini (56)

Open Models (1)

Partner Models (1)

SDK (1)

Vertex AI Search (2)

Workshops (1)


Part of the Generative AI Google Brain · Function Calling & Tools - Best Practices