Agents & ADK — Best Practices
Distilled from 72 notebooks tagged Agents & ADK in the GoogleCloudPlatform/generative-ai repository. The From the notebooks section below cites the per-notebook source for grounding.
Do this
- Test tool functions directly before wiring them into an agent, and test the full agent locally before deploying to Agent Engine or Agent Runtime.
- Keep deployment constructors lightweight and pickle-able; move heavy initialization into set_up and use root_agent.py or ModuleAgent when local objects contain non-serializable MCP or registry state.
- Wrap ADK agents in AdkApp for Agent Engine deployment and list all runtime dependencies explicitly in requirements, build options, source packages, or container configuration.
- Store production session state outside the agent runtime with VertexAISessionService, especially for Cloud Run, GKE, or scaled deployments where in-memory state is unreliable.
- When using ADK memory tools, provide both the memory tool on the Agent and the memory_service on the Runner; provide a session_service on the Runner when using managed sessions.
- Scope Memory Bank data with stable keys such as user_id, use PreloadMemoryTool or semantic retrieval for relevant context, and use TTL, managed topics, and revision labels for governance.
- Generate memories from complete sessions or incremental recent events, and decide deliberately between blocking wait_for_completion and background memory generation.
- Use environment variables, Application Default Credentials, refreshed OAuth credentials, and IAM roles instead of hardcoded secrets; mask tokens and avoid committing API keys.
- Define A2A Agent Cards with clear skills, descriptions, tags, examples, input modes, and output modes, and use context_id or session_id to preserve continuity across interactions.
- For A2A and data-agent calls, handle both task and direct-message responses, use UUID message IDs, poll terminal task states with bounded backoff, and inspect artifacts as well as message content.
- Discover and enable MCP or Cloud API Registry tools before use, verify tool availability, inspect datasets and schemas before querying, and prefer real tool results over model assumptions.
- Run generated or untrusted code in Agent Engine Sandbox, parse outputs by mime_type and metadata, and return function_response or tool_result messages before asking the model for a final answer.
- Evaluate agents with online and offline signals, reference trajectories, tool-selection metrics, trajectory metrics, response quality metrics, latency, failure rate, and tracing where available.
- Use structured JSON outputs, response schemas, Pydantic validation, low temperature, and seeds for guardrail classifiers or deterministic tool-review examples.
- Delete Agent Engine deployments, sandboxes, Cloud Run services, GKE resources, Cloud SQL instances, staging buckets, experiments, and test agents after tutorials to avoid ongoing charges.
Avoid this
- Starting before the project has billing, required APIs, authentication, IAM roles, region, staging bucket, and environment variables correctly configured.
- Assuming Colab behaves like local development; many notebooks require explicit Colab authentication, package-install runtime restarts, nest_asyncio, or asyncio.run for ADK async APIs.
- Using InMemorySessionService for production or scaled deployments, which loses state on shutdown and does not work reliably across multiple Cloud Run or GKE instances.
- Changing Memory Bank scope keys, expecting every conversation to create memories, or expecting non-blocking memory writes to be immediately retrievable.
- Serializing agents with non-pickleable state in init, local registry clients, MCPToolset objects, or missing deployment dependencies instead of using set_up, root_agent.py, ModuleAgent, or explicit requirements.
- Hardcoding Reddit credentials, API keys, access tokens, service account paths, or using unauthenticated Cloud Run settings as if they were production defaults.
- Ignoring preview, pre-GA, region, model-availability, Express Mode, streaming, cancellation, or SDK-update limitations called out in the notebooks.
- Forgetting cleanup, which can leave deployed agents, sandboxes, sessions, memories, buckets, clusters, repositories, experiments, or databases billing after the tutorial.
From the notebooks
Get started with Vertex AI Memory Bank
- Use a stable user_id scope to retrieve memories for a specific guest.
- Store the complete conversation in a session before generating memories.
- Use scope-based retrieval for complete profiles or small memory sets.
- Use similarity search for specific questions, many memories, fast targeted responses, or conversational context.
- Delete the Agent Engine and memories after the tutorial to avoid charges.
Governance with Vertex AI Memory Bank
- Use GenerateMemories with direct_memories_source or direct_contents_source when consolidation is needed instead of manual create.
- Set granular TTL values for different memory creation and update paths.
- Use scopes such as user_id to isolate customer memories.
- Use managed topic labels to filter customer data by category.
- Use revision labels such as data_source and verified for governance workflows.
Get started with Memory Bank on ADK
- Use add_events_to_memory for production agents to stream recent events incrementally.
- Use add_session_to_memory at the end of a session when processing the whole session is acceptable.
- Provide both a memory tool on the Agent and a memory service on the Runner when using built-in ADK memory tools.
- Use callbacks to automate memory generation after turns.
- Use Agent Engine SDK generate with wait_for_completion when blocking memory generation is required.
Building a Multimodal Trip Planner with ADK on Vertex AI Agent Engine Memory Bank
- Use managed topics for common memory categories and custom topics for domain-specific memory extraction.
- Provide text context alongside file_data so multimodal memories are grounded in user intent.
- Scope generated memories with user_id.
- Use PreloadMemoryTool so relevant memories are fetched at the start of a conversation turn.
- Instruct the agent not to make up facts when memories are unavailable.
Get started with A2A on Agent Engine
- Test the A2A agent locally with set_up before deploying to Agent Engine.
- Define an AgentSkill with id, name, description, tags, examples, input modes, and output modes.
- Use context_id as the Vertex session_id to preserve continuity across A2A interactions.
- Use VertexAiSessionService when GOOGLE_CLOUD_AGENT_ENGINE_ID is present and InMemorySessionService for local execution.
- Return final answers as A2A artifacts and update task state through TaskUpdater.
Getting Started with Bidirectional Streaming v2 on Agent Runtime
- Use bring-your-own-Dockerfile deployment with source_packages for custom Agent Runtime servers.
- Set GOOGLE_GENAI_USE_VERTEXAI to 1 for the deployed ADK agent environment.
- Use resource_limits and max_instances in Agent Runtime deployment config.
- Refresh google.auth credentials before making HTTP or WebSocket calls.
- Separate receive and send loops for bidirectional WebSocket handling.
Claude with ADK on Vertex AI Agent Engine
- Test the ADK agent locally with InMemorySessionService and Runner before deploying.
- Package the deployable agent in a root_agent.py module and expose an AdkApp entry point.
- Use a VertexAiSessionService builder for production sessions on Agent Engine.
- Pass runtime credentials and model settings through environment variables for the deployed app.
- Use build_options installation steps to install external MCP runtime dependencies during deployment.
Deploy your containerized agent on Agent Runtime (prev. Agent Engine)
- Stores project, model, model region, and location settings in config.json for the containerized agent.
- Uses a Dockerfile and requirements.txt to make the agent runtime reproducible.
- Wraps the ADK root_agent with agent_engines.AdkApp before exposing runtime endpoints.
- Defines both regular and streaming FastAPI endpoints for agent invocation.
- Uses agent_framework=“google-adk” so the deployed agent can be used through the Google Cloud console playground.
Deploy your first agent to Vertex AI Agent Engine
- Start with Express Mode if new to Vertex AI Agent Engine.
- Do not share or commit API keys publicly.
- Use agent object deployment for interactive development in notebook environments like Colab.
- Wrap ADK agents in AdkApp before deploying to Agent Engine.
- Enable tracing on AdkApp for debugging.
Get started with Agent Engine Terraform Deployment
- Use Terraform configuration files for version-controlled, repeatable Agent Engine deployments.
- Define class_methods for the operations the deployed agent supports.
- Package requirements.txt, agent.pkl, and dependencies.tar.gz as deployment artifacts.
- Use set_up() for initialization logic and keep init() configuration pickle-able.
- Use terraform output to retrieve deployed Reasoning Engine resource information.
Get started with Cloud API Registry on Vertex AI Agent Engine
- Discover MCP servers and tools before enabling and using them.
- Verify the BigQuery MCP server shows as ENABLED after enabling it.
- Use x-goog-user-project in the ApiRegistry header provider for BigQuery MCP access.
- Explore datasets and table schemas before writing SQL queries.
- Use BigQuery tools to fetch real data rather than making assumptions.
Get started with Code Execution on Vertex AI Agent Engine
- Run generated or untrusted code in an isolated Agent Engine Sandbox instead of the host system.
- Initialize Vertex AI with explicit project and location before creating Agent Engine resources.
- Parse sandbox outputs by mime_type and metadata, handling stdout, stderr, and generated files separately.
- Use temperature=0 for the Gemini tool-calling example to make the function-call flow more deterministic.
- Send function_response or tool_result messages back to the model before asking for the final answer.
Getting Started with Live API on Agent Engine
- Keep init lightweight and pickle-able for Agent Engine serialization.
- Put heavy initialization in set_up because Agent Engine calls it when the serverless container starts.
- Make each stream_query yield a complete serializable response object.
- Use bidi_stream_query with asyncio.Queue for continuous two-way sessions.
- Declare agent dependencies in the Agent Engine requirements config.
MCP on Vertex AI Agent Engine with custom installation scripts
- Test the agent locally with InMemorySessionService and Runner before deploying to Agent Engine.
- Use environment variables for Google Cloud settings and Reddit credentials.
- Use one chat_loop abstraction for local Runner and remote AgentEngine or AdkApp testing.
- Close the aiofiles error log in a finally block after local testing.
- Wrap the deployed ADK app in root_agent.py and reference it with ModuleAgent when MCPToolset is used.
Building multi-agent systems with Vertex AI and Claude
- Test Bear and Bull agents locally before deployment.
- Use environment variables for ADK and Vertex AI project configuration.
- Define A2A agent cards with skills, descriptions, tags, and examples for discovery.
- Package MCP tools as importable Python modules with a stdio server entry point.
- Use lazy initialization for deployed agents to avoid pickling issues.
Building Multi-Agent Systems with Vertex AI and Llama model
- Test the Bear and Bull agents locally before deployment.
- Use separate role-specific prompts for risk-focused and opportunity-focused agents.
- Expose agent capabilities through A2A Agent Cards with skills, tags, and examples.
- Package MCP tools as importable modules with a separate stdio server entry point.
- Use lazy initialization in deployed executors to avoid pickling issues.
Get started with Sessions and Memory Bank for ADK agents in Cloud Run
- Store production ADK session data outside the agent runtime.
- Use VertexAISessionService for scalable managed session storage.
- Provide a memory tool on the Agent and a memory_service on the Runner.
- Use a session_service on the Runner when using managed sessions.
- Create new sessions during testing to prove long-term memory carries across sessions.
Gemini Data Analytics: A2A HTTP API Sample
- Retrieve the Agent Card first to verify connectivity and agent capabilities.
- Use uuid.uuid4() to create unique message_id values.
- Use blocking=False for long-running tasks and poll terminal task states.
- Use bounded backoff while polling task status.
- Inspect both task artifacts and direct message content or metadata.
Gemini Data Analytics: A2A SDK API Sample
- Use Google Cloud user authentication and refresh credentials before creating the client.
- Pass the bearer token through an httpx.AsyncClient Authorization header.
- Use the high-level a2a-sdk instead of manual stubs.
- Enable streaming and polling in ClientConfig.
- Use a UUID for each A2A message_id.
Intro to Gemini Data Analytics
- Provide business and data context in system_instruction to improve answer quality.
- Use structured datasource references for BigQuery, Looker, or Looker Studio.
- Add BigQuery example queries and glossary terms when available.
- Use validated Looker golden queries when using Looker context.
- Preserve existing IAM policy by getting it before setting updated permissions.
Get started with Sessions and Memory Bank for ADK agents in Google Kubernetes Engine
- Store production ADK session data outside the agent runtime.
- Use VertexAISessionService for scalable managed session storage.
- Use VertexAiMemoryBankService for persistent long-term memory.
- Provide both a memory tool on the Agent and a memory service on the Runner.
- Provide a session service on the Runner when using managed sessions.
Intro to Managed Agents API on Agent Platform (cURL)
- Validate authentication, API enablement, service agent role, and user IAM access before creating agents.
- Use a targeted system_instruction to tailor custom agent behavior.
- Delete custom agent configurations when no longer needed to keep the project clean.
- Use update_mask when patching mutable agent fields.
- Mount Cloud Storage sources into a remote environment instead of embedding skill content in requests.
Intro to Managed Agents API on Agent Platform (Python)
- Validate authentication, API enablement, service agent role, and user access before creating agents.
- Use unique agent IDs with uuid to avoid naming collisions.
- Poll agent creation status with client.agents.get because creation is asynchronous.
- Delete test agents after the demo to keep the project clean.
- Reuse environment IDs when filesystem or execution context must persist across turns.
Managed Agents API - Analyzing the 2026 World Cup
- Validate project API enablement and IAM roles before creating the agent.
- Mask access tokens in logs instead of printing full secrets.
- Refresh OAuth tokens when missing or expired.
- Use timezone-aware UTC expiry checks for credentials.
- Keep agent skills in a configured Cloud Storage bucket or use the Google Cloud Skills Registry.
- Use a mandatory SKILL.md file with YAML frontmatter and markdown instructions.
- Make the skill name a unique identifier matching the skill package name.
- Start the skill description in third person as a capability statement.
- Use local_path so the SDK packages, compresses, uploads, provisions, and indexes the skill.
- Use timestamped skill IDs to avoid collisions during registration.
🛡️ AI Brand Safety: Three-Tier Agent Anomaly Detection
- Compare prompts, tool calls, and responses against separate Vector Search indices to reduce structural false positives.
- Generate industry-specific golden baselines using the agent instruction and INDUSTRY_VERTICAL.
- Request JSON from Gemini with response_mime_type=“application/json” and parse it with json.loads.
- Log full execution traces to BigQuery as a flight recorder for later threshold tuning without new LLM calls.
- Route safety finish reasons and novelty anomalies to Tier 1 for 100% audit.
Vertex AI Agent Engine in Express Mode
- Test the tool function directly before adding it to the agent.
- Test the ADK agent locally before deploying it to Agent Engine.
- Declare class_methods for the deployed async streaming and session methods.
- Use source based deployment with source_packages, entrypoint_module, entrypoint_object, and requirements_file.
- Inspect session events after remote conversations to view stored conversation history.
Evaluate a CrewAI agent on Vertex AI Agent Engine (Customized template)
- Evaluate agents both online and offline, using subjective and objective evaluation signals.
- Track single tool selection, trajectory order, response generation, latency, and failure rate when evaluating agents.
- Use reference trajectories in the evaluation dataset when checking expected tool calls.
- Wrap custom agent output so it includes response and predicted_trajectory for evaluation.
- Clean up experiments and remote agents after the notebook run.
Evaluating a LangChain Agent on Vertex AI Agent Engine (Prebuilt template)
- Evaluate agents with both objective metrics and subjective feedback to build trust in behavior.
- Use agent_executor_kwargs={“return_intermediate_steps”: True} so tool calls can be evaluated.
- Prepare evaluation data with prompts and reference trajectories for tool and trajectory metrics.
- Evaluate single tool selection before broader trajectory and response quality metrics.
- Use custom pointwise metrics when response quality depends on whether the response follows tool choices.
Evaluate a LangGraph agent on Vertex AI Agent Engine (Customized template)
- Evaluate agents both online and offline using subjective and objective signals.
- Use prompts, reference responses, and reference trajectories in evaluation datasets when available.
- Start with single tool selection, then evaluate full trajectories and generated responses.
- Use trajectory metrics such as exact match, in-order match, any-order match, precision, and recall.
- Parse custom agent output into response and predicted_trajectory before passing it to EvalTask.
Intro to Building and Deploying an Agent with Agent Engine in Vertex AI
- Test the Python tool directly before wiring it into the agent.
- Test the agent locally with query before deployment.
- Use stream_query to observe actions, messages, and output for debugging or real-time updates.
- Re-define the agent before deployment to avoid stateful information from local testing.
- Record remote_agent.resource_name so the deployed agent can be reused from another Python environment.
Persisting LangChain History with Vertex AI Session Service
- Store the full LangChain message payload with message_to_dict instead of only message text.
- Use messages_from_dict to reconstruct LangChain messages from stored raw_event payloads.
- Wrap chains with RunnableWithMessageHistory to centralize history injection and persistence.
- Use strict system instructions when the model must call a tool instead of using internal knowledge.
- Delete the Agent Engine with force=True after the demo to clean up sessions.
Building and Deploying a Human-in-the-Loop LangGraph Application with Agent Engine on Vertex AI
- Initialize Vertex AI with project, location, and staging bucket before using Agent Engine.
- Set temperature to 0 for deterministic tool-review examples.
- Use max_retries for model calls in the LanggraphAgent configuration.
- Call agent.set_up() before local testing.
- Use interrupt_before and interrupt_after around tools for human oversight.
Get started with Vertex AI Memory Bank - ADK
- Use a unique USER_ID to scope memories to a particular user.
- Use PreloadMemoryTool so the agent can retrieve relevant user context.
- Prompt the agent to personalize responses and naturally reference past conversations when relevant.
- Retrieve the completed session before adding it to Memory Bank.
- Delete the Agent Engine after experimentation to avoid charges.
Get started with Vertex AI Memory Bank - CrewAI
- Validate project, location, and Agent Engine name before using custom storage.
- Scope memories by user_id to keep user memory separated.
- Use wait_for_completion when generating memories before retrieval is expected.
- Create a new Vertex AI client per storage operation for async event loop management.
- Delete the Agent Engine resource after the tutorial to avoid ongoing charges.
Get started with Vertex AI Memory Bank - LangGraph
- Scope memories by user_id so retrieved facts are user-specific.
- Retrieve memories before generation and inject them into the system prompt.
- Use semantic search with top_k to limit retrieved memories to relevant facts.
- Store both user and model messages after each turn to continuously build memory.
- Use wait_for_completion when generating memories so persistence completes before continuing.
AG2 (formerly Autogen) Multi-Agents Example on Vertex AI Agent Engine
- Authenticate in Colab with google.colab.auth or use Application Default Credentials outside Colab.
- Test ResearchApp locally before deploying to Vertex AI Agent Engine.
- Use Cache.disk() to reduce inference cost.
- Use human_input_mode=“NEVER” for the deployed UserProxyAgent query flow.
- Clean up deployed Agent Engines to avoid unnecessary costs.
Building and Deploying a LangGraph Agent with Agent Engine in Vertex AI
- Test the LangGraph agent locally before deployment.
- Provide deployment requirements in the Agent Engine config.
- Use a staging bucket for Agent Engine deployment artifacts.
- Delete the deployed agent after experimentation.
- Optionally delete the staging bucket after cleanup.
Building a Multi-Agent RAG Application with LangGraph and Agent Engine
- Pin deployment requirements to the same package versions used in the notebook.
- Test the LangGraph app locally before deploying it to Agent Engine.
- Use separate vector store tables for movie and book data.
- Use Cloud Storage as the source for reusable JSON document datasets.
- Clean up Agent Engine apps and Cloud SQL instances after the tutorial to avoid billing.
- Use function declarations to constrain database access instead of generating and executing arbitrary SQL.
- Use BigQuery query parameters for filters such as price, store IDs, radius, product ID, and store ID.
- Cap requested result counts with MAX_PRODUCT_RESULTS and MAX_STORE_RESULTS.
- Use semantic search only when product_search_query is provided, otherwise use standard SQL filtering.
- Execute multiple function calls asynchronously and feed function responses back to the model.
- Use a dedicated guardrails node before the chat node to decide whether to answer or block.
- Use temperature=0 and seed=0 for guardrail classification consistency.
- Return structured JSON with response_schema and validate it with Pydantic.
- Provide a safe guardrail_response for blocked requests.
- Store conversation history in state so the classifier and chat node can use prior turns.
- Use a structured Pydantic schema for router output instead of parsing free-form text.
- Keep router temperature low and seed fixed for more deterministic classification.
- Store user and model messages per turn so later calls can include conversation history.
- Route unsupported inputs to a fallback response instead of an expert node.
- Use LangGraph MemorySaver with thread_id to preserve session-specific state.
- Use Pydantic models for Task, Plan, Response, and PlanOrRespond to keep agent decisions structured.
- Reset task results to None before executing newly generated plan tasks.
- Separate planning, execution, reflection, and post-processing into explicit LangGraph nodes.
- Use Google Search grounding in the executor for research tasks requiring live information.
- Use a MemorySaver checkpointer and thread_id to preserve conversation state across turns.
- Define an explicit TypedDict state schema before constructing the StateGraph.
- Return types.Command from nodes to update state and route execution.
- Use separate stream modes to inspect debug events, full values, and node updates.
- Use unique uuid.uuid4().hex thread IDs for stateful stream calls.
- Build a separate agent with checkpointer_config=None for stateless requests.
Query a Remote LangGraph Agent Server
- Use a unique thread_id to keep each test session isolated.
- Pass an Authorization bearer header only when an id_token is available.
- Handle multiple chunk shapes explicitly, including text, responses, guardrail classifications, router classifications, function calls, function responses, plans, executed tasks, errors, and unhandled keys.
- Use get_state and get_state_history to inspect the remote agent session after streaming.
Intro to Computer Use with Gemini
- Run Computer Use agents in a secure controlled environment such as a sandboxed VM, container, or dedicated browser profile.
- Implement client-side action handling and screenshot capture.
- Append both model responses and function responses to conversation history.
- Return a FunctionResponse for each executed action, including parallel actions.
- Handle missing candidates because safety filters may return no candidates.
Introduction to Gemini Deep Research Agent
- Save the interaction_id immediately after initialization.
- Use specific formatting instructions in the prompt to shape reports, sections, tables, and tone.
- Prompt the agent to state when data is unavailable instead of estimating it.
- Be cautious when combining sensitive internal data with public web browsing.
- Verify citations returned by the agent.
Create & Deploy Agent and Run Gen AI Agent Evaluation
- Create a small agent-specific evaluation dataset before running evaluation.
- Run inference first so the dataset contains response and intermediate_events columns.
- Use AgentInfo.load_from_agent with the agent definition and deployed resource name.
- Persist managed evaluation results to Cloud Storage when results need to be retrieved later.
- Poll evaluation runs until they reach SUCCEEDED, FAILED, or CANCELLED before displaying final results.
Create a Gen AI Agent Evaluation for a Deployed Agent
- Run inference first so the dataset includes intermediate_events and response columns before evaluation.
- Persist evaluation datasets and results to a Cloud Storage destination.
- Provide AgentInfo with agent instruction and tool definitions for agent evaluation.
- Poll the evaluation run until SUCCEEDED, FAILED, or CANCELLED before retrieving full results.
- Retrieve with include_evaluation_items=True to inspect detailed evaluation items.
Evaluate agent final answer with custom parsing
- Use a human reference response as the golden answer for judging agent output validity.
- Request structured JSON from the autorater when downstream parsing is needed.
- Use CustomOutputConfig with a parsing function to append parsed output to evaluation results.
- Return raw autorater output alongside parsed results for inspection.
- Separate helper functions, prompt template, metric definition, dataset preparation, and evaluation execution.
Evaluating Agents - Evaluate a CrewAI agent with Vertex AI Gen AI Evaluation Service
- Evaluate agents with both monitoring-style task metrics and observability considerations such as latency and failure rate.
- Use reference trajectories to evaluate expected tool choices and ordering.
- Start with single-tool usage evaluation before broader trajectory evaluation.
- Evaluate final responses separately from tool trajectory quality.
- Use custom pointwise metrics when standard text metrics are insufficient for agent behavior.
Evaluating Agents - Evaluate a LangGraph agent with Vertex AI Gen AI Evaluation Service
- Use an experiment name when initializing Vertex AI to organize evaluation runs.
- Include prompts and reference trajectories in the evaluation dataset for agent trajectory metrics.
- Evaluate single tool use before broader trajectory and response evaluations.
- Use multiple trajectory metrics to compare exact order, in-order match, any-order match, precision, and recall.
- Use custom pointwise metrics when response quality depends on the agent’s tool trajectory.
Evaluate your ADK agent using Vertex AI Gen AI Evaluation service
- Use a small reference dataset with prompts and expected tool trajectories.
- Evaluate single tool selection before broader trajectory metrics.
- Track evaluation runs with unique experiment run names.
- Separate trajectory metrics from response metrics such as safety and coherence.
- Use custom pointwise criteria when response quality depends on tool choices.
- Load API keys from environment variables and prompt with getpass when missing.
- Use explicit task context to enforce sequential dependencies between agents.
- Store test inputs and expected reference trajectories in a Phoenix dataset.
- Evaluate trajectories with multiple metrics: exact match, precision, in-order match, and any-order match.
- Add a custom code evaluator for agent-name order matching.
Gen AI Eval - Multi-turn Agent Eval, User Simulation, Metric Registration, Auto-Loss Analysis
- Load AgentInfo from the ADK agent before scenario generation.
- Throttle evaluation calls with evaluation_service_qps.
- Register custom metrics once and reference their metric_resource_name in evaluation runs.
- Return a dictionary from custom LLM metric result_parsing_function.
- Use predefined multi-turn metrics for tool use quality, trajectory quality, and task success.
View Gen AI Agent Evaluation Run Results
- Install google-cloud-aiplatform[evaluation] before using evaluation features.
- Use include_evaluation_items=True when detailed case-level results are needed.
- Use evaluation_run.show() to visualize failed run errors or embedded evaluation reports.
Intro to Model Context Protocol (MCP) integration with Vertex AI
- Use environment variables for project and region when explicit values are not provided.
- Validate and normalize tool inputs such as two-letter US state codes.
- Handle HTTP status errors, timeouts, request errors, JSON decode errors, and unexpected exceptions in external API calls.
- Return structured tool responses with either result or error payloads.
- Use a maximum tool-turn limit to avoid endless tool-calling loops.
From API to Report: Building a Currency Analysis Agent with LangGraph and Gemini
- Separate the workflow into distinct nodes for API interaction, data validation, and report generation.
- Use LangChain tools to expose external data sources to the agent.
- Use conditional graph edges to route between tool execution and review.
- Compile the graph with MemorySaver to support state management.
- Use system and user prompts to define tool usage and the analysis task.
Build Your Own AI Podcasting Agent with LangGraph, Gemini, and Chirp 3
- Defines AgentState with typed workflow fields for task, outline, queries, content, draft, critique, and tool calls.
- Uses MemorySaver and thread_id to preserve unique workflow execution history.
- Uses temperature=0 for deterministic agent node outputs.
- Limits arXiv retrieval with load_max_docs=2 and get_full_documents=False.
- Prompts the research agent to vary tools and avoid repeating prior sources and queries.
LlamaIndex RAG Workflows using Gemini and Firestore
- Pin LlamaIndex package versions used by the workflow.
- Use google.auth.default with quota_project_id and refresh credentials before model setup.
- Configure safety settings for dangerous content, harassment, and sexually explicit content.
- Set Settings.embed_model and Settings.llm so LlamaIndex components share the same Vertex models.
- Use custom Event classes to make workflow transitions explicit.
🛡️ Agentic GraphRAG: Cybersecurity Threat Intelligence
- Authenticate in Colab with google.colab.auth.authenticate_user when running in Colab.
- Use vertexai.init with explicit project and location before Vertex AI operations.
- Re-initialize Neo4j and imports inside the tool function for serialization contexts.
- Give the ADK agent explicit instructions to use query_threat_graph first for threats, actors, and CVEs.
- Test the ADK app locally before deploying to Vertex AI Agent Engine.
GraphRAG on Google Cloud With Spanner and Vertex AI Agent Engine
- Constrain graph extraction with allowed_nodes and allowed_relationships.
- Use temperature=0 for deterministic graph Q&A and entity rewriting.
- Store embeddings alongside graph-related text in Spanner for semantic matching.
- Combine vector search with graph search when exact graph entity names may not match user phrasing.
- Configure ADK instructions to check the graph database before broader Google Search.
🌿 Eco-Nomad Swarm: 100% Real-Data Sustainable Travel Orchestration
- Use live databases or real-world REST endpoints instead of mocked travel, weather, forex, or translation data.
- Chain tool outputs deterministically, such as graph-derived country to RESTCountries currency to Frankfurter forex conversion.
- Keep agent tools narrow and domain-specific: graph routing, demographics, treasury, climate, web intelligence, and translation.
- Use exact 3-letter currency codes for live currency conversion.
- Initialize Vertex AI with project, region, and a staging bucket before production deployment.
Building an ADK agent using QWEN 3 on Vertex AI
- Smoke test the deployed model endpoint with LiteLLM before building the full ADK agent.
- Use InMemorySessionService and adk.Runner to test agent behavior locally before deployment.
- Wrap Python functions with FunctionTool so ADK can call them as tools.
- Use reasoning_engines.AdkApp before deploying the ADK agent to Agent Engine.
- Delete the Vertex AI Endpoint and Agent Engine after use to avoid ongoing charges.
Running Qwen 3 with Ollama in Cloud Run for Agents
- Keep the Cloud Run service private with —no-allow-unauthenticated and use IAM authentication.
- Use a dedicated service account for the Cloud Run service.
- Set OLLAMA_KEEP_ALIVE=-1 so model weights are not unloaded from GPU memory.
- Warm the model at startup with a dummy ollama run request.
- Set temperature=0.1 for stable function calling.
Running a Gemma 2-based agentic RAG with Ollama on Vertex AI and LangGraph
- Use a Cloud Storage staging bucket when initializing Vertex AI SDK.
- Use Artifact Registry and Cloud Build to build and store the custom serving image.
- Expose Vertex AI-compatible health and predict routes in the custom container.
- Validate prediction requests and return consistent error responses in the FastAPI proxy.
- Test the serving container locally with Vertex AI LocalModel before deploying when debugging.
Build and deploy a Hugging Face smolagent using DeepSeek-r1 on Vertex AI
- Use environment variables GOOGLE_CLOUD_PROJECT and GOOGLE_CLOUD_REGION as fallbacks for project and location.
- Initialize vertexai with project, location, and staging_bucket before creating Vertex AI resources.
- Use Vertex AI Model Registry to manage the imported Hugging Face model lifecycle.
- Use a dedicated endpoint display name derived from the model ID.
- Set explicit serving container predict route, health route, port, and environment variables for the vLLM container.
Gemini Enterprise custom agent with prompt management
- Create the managed prompt once and reuse its prompt_id rather than hard-coding instructions in the deployed agent.
- Fetch the prompt in before_agent_callback so prompt text is centrally managed.
- Pass schema DDL as a text/plain file part instead of assuming schema context.
- Use low temperature for SQL generation.
- Enable tracing in AdkApp for local testing.
Gemini Enterprise custom agent with Vertex AI session
- Use VertexAiSessionService when an agent needs persistent session state.
- Split agent responsibilities into query completeness checking and itinerary generation.
- Use a low temperature of 0.01 for the root agent configuration.
- Use a session_service_builder when creating reasoning_engines.AdkApp.
- Test the same multi-turn queries locally and through the remote Agent Engine app.
MCP Server with Gemini Enterprise
- Keep the MCP server private on Cloud Run with —no-allow-unauthenticated.
- Use environment variables for project, dataset, table, host, port, and region configuration.
- Test the ADK agent locally with reasoning_engines.AdkApp before deploying to Agent Engine.
- Declare Agent Engine runtime requirements explicitly when creating the remote app.
- Use a structured agent instruction that asks for employee ID, start date, and end date before applying leave.
Open Source Models (Gemma) as a agent with Gemini Enterprise
- Deploy the open-source model first, then integrate it through a tool function before agent deployment.
- Keep the Cloud Run model endpoint private and authenticate with an ID token.
- Test the ADK app locally with a session and stream_query before creating the remote Agent Engine app.
- Pin runtime requirements when deploying the agent to Agent Engine.
- Use a staging bucket when initializing Vertex AI for Agent Engine deployment.
AI Agents for Engineers (Evolution of AI Agents)
- Use temperature=0 for deterministic LangChain and LangGraph essay workflows.
- Verify whether the GenAI client is using Gemini Developer API, Vertex AI project/location, or Vertex AI express mode.
- Use Tavily search when the prompt asks about recent events that the model may not know.
- Separate planning, research, writing, reflection, and critique research into explicit LangGraph nodes.
- Compile the graph with MemorySaver and run it with a thread_id for state management.
Back to Agents & ADK · Best Practices Map