Building adk agents

From jchavezar/vertex-ai-samples · View interactive version

Building adk agents is an AI agent skill from the GitHub repository jchavezar/vertex-ai-samples. Guides the creation of Google ADK (Agent Development Kit) agents. Use when the user asks to create, configure, or understand ADK agents, workflows, or tools.

How to use this skill

Skill file

Building Google ADK Agents

When to use this skill

Mandatory Model Versions

CRITICAL: You must ONLY use the following models. NO gemini-1.5 or gemini-2.0 (unless flash), and NO text-bison:

```python

import vertexai

from vertexai.agent_engines import AdkApp

from google.adk.agents import LlmAgent

```

Structured Output (JSON Schema)

When an agent needs to produce structured data (JSON), ALWAYS use output_schema with a Pydantic model. This enforces strict JSON output from the model.

Important: Use output_key to automatically store the parsed JSON in the session state.

Python Example

from pydantic import BaseModel, Field
from google.adk.agents import LlmAgent

# 1. Define Pydantic Schema
class CapitalOutput(BaseModel):
    capital: str = Field(description="The capital of the country.")
    population: int = Field(description="Population of the capital.")

# 2. Register Agent
structured_capital_agent = LlmAgent(
    name="capital_agent",
    model="gemini-3-flash-preview",
    instruction="You are a Capital Information Agent. Given a country, respond ONLY with JSON.",
    output_schema=CapitalOutput,  # Enforces JSON output format
    output_key="found_capital"    # Stores dict result in ctx.session.state['found_capital']
)

TypeScript Example

import { z } from 'zod';
import { Schema, Type } from '@google/genai';
import { LlmAgent } from '@google/adk';

// 1. Define Schema using @google/genai types
const CapitalOutputSchema: Schema = {
    type: Type.OBJECT,
    properties: {
        capital: { type: Type.STRING, description: 'The capital city.' },
    },
    required: ['capital'],
};

// 2. Register Agent
const agent = new LlmAgent({
    name: 'capital_agent',
    model: 'gemini-3-flash-preview',
    instruction: 'Respond with JSON.',
    outputSchema: CapitalOutputSchema,
    outputKey: 'found_capital',
});

Java Example

// Define Schema
Schema capitalOutput = Schema.builder()
    .type("OBJECT")
    .properties(Map.of("capital", Schema.builder().type("STRING").build()))
    .build();

LlmAgent agent = LlmAgent.builder()
    .model("gemini-3-flash-preview")
    .outputSchema(capitalOutput)
    .outputKey("found_capital")
    .build();

Search Fallback Policy

CRITICAL: If you cannot find the answer in this skill or your existing knowledge, you MUST use the brave_web_search tool (available via brave-search MCP) to find the latest documentation, error fixes, or examples. Do not hallucinate API methods.

Workflow

[ ] Define Agent Type: Determine if you need a single LlmAgent or a workflow (SequentialAgent, ParallelAgent, LoopAgent).

[ ] Define Tools: Identify necessary tools (Google Search, Custom Python Functions, MCP).

[ ] Create Agent File: Scaffold the agent class/definition in Python (or requested language).

[ ] Setup Runner: Create the main entrypoint with Runner and InMemorySessionService (or other).

[ ] Validation: Ensure type hints in tools are correct for auto-schema generation.

Instructions

  1. Read the Docs First: This skill includes a distilled documentation set in resources/distilled/. Always check these high-density files first for specific implementation details.
  1. Core Components:
  1. Tooling:
  1. State Management:

Common Pitfalls & Guardrails

Resources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.