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. Expert guide for building, deploying, and debugging Google ADK (Agent Development Kit) agents. Use for creating LLM agents, workflows, tools, and multi-agent systems.

How to use this skill

Skill file

Building Google ADK Agents (Expert Mode)

p

When to use this skill

🚨 Critical Mandates

  1. Model Selection:
  1. Structured Output:
  1. Code Quality:
  1. Environment & Execution:

🧠 Knowledge Base

This skill is backed by the full ADK documentation.

🛠️ Implementation Patterns

1. Structured Output (JSON)

Enforce strict schema adherence for reliable downstream processing.

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

# 1. Define Schema
class ResearchResult(BaseModel):
    summary: str = Field(description="Executive summary of findings")
    sources: list[str] = Field(description="List of URLs cited")

# 2. Configure Agent (Consolidated Agent class)
agent = Agent(
    name="researcher",
    model="gemini-3.1-flash-lite",
    instruction="Analyze the given topic and return structured data.",
    output_schema=ResearchResult,  # <--- CRITICAL
    output_key="research_data"     # <--- Stores in ctx.session.state['research_data']
)

2. State & Artifacts

Manage conversation context and binary files (PDFs, Images).

from google.adk.agents import CallbackContext

async def my_tool(ctx: CallbackContext, data: str):
    # Access Session State
    user_id = ctx.session.state.get("user_id")
    
    # Save Binary Artifact (e.g., generated PDF)
    await ctx.save_artifact(
        filename="report.pdf", 
        artifact=pdf_bytes, 
        mime_type="application/pdf"
    )

3. Workflow Construction

Compose agents into deterministic or dynamic flows.

from google.adk.agents import SequentialAgent

workflow = SequentialAgent(
    name="blog_post_workflow",
    agents=[researcher_agent, writer_agent, editor_agent],
    output_key="final_post"
)

✅ Development Checklist

  1. Define Strategy:
  1. Scaffold:
  1. Implement Tools:
  1. Verify:

4. Next-Gen Agent Engine Deployment

Utilize the vertexai.Client and vertexai.agent_engines.AdkApp pattern for robust Cloud deployments.

import vertexai
from vertexai.agent_engines import AdkApp

# 1. Initialize with Client
client = vertexai.Client(project="PROJ", location="LOC")

# 2. Wrap Agent
deployment_app = AdkApp(agent=root_agent, enable_tracing=True)

# 3. Idempotent Update or Create
all_engines = list(client.agent_engines.list())
target = next((e for e in all_engines if e.api_resource.display_name == "MY_APP"), None)

if target:
    remote_app = client.agent_engines.update(
        name=target.api_resource.name,
        agent=deployment_app,
        config={"display_name": "MY_APP", "staging_bucket": "gs://...", "requirements": "requirements.txt", "extra_packages": ["agent.py"]}
    )
else:
    remote_app = client.agent_engines.create(
        agent=deployment_app,
        config={"display_name": "MY_APP", "staging_bucket": "gs://...", "requirements": "requirements.txt", "extra_packages": ["agent.py"]}
    )

🛑 Common Pitfalls to Avoid

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.