Lab 30.1: Spec-Driven Scaffolding, Stateful Triage & Built-In A2A
Goalโ
In this kickoff lab for Part 6: Enterprise AgentOps with Google Agents CLI, you will install and configure google-agents-cli v1.10, sync the 7 AgentOps coding-agent skills, scaffold our canonical support-ops-agent in --prototype mode, author its Phase 0 architectural contract (.agents-cli-spec.md), implement stateful ticket triage and P1 escalation tools in app/agent.py (gemini-3.8-flash), run multi-turn verbose smoke tests against a persistent local server, inspect the built-in A2A AgentCard, and preview 3-way template maintenance with scaffold upgrade --dry-run.
Every subsequent module in Part 6 (Evaluation & GEPA in Module 30.2, Extensions & GitOps CI/CD in Module 30.3, Cloud Telemetry & Cost Control in Module 30.4) and Part 7 (Cloud Run, GKE, Agent Runtime, and Gemini Enterprise in Modules 31โ36) builds directly on the support-ops-agent repository you create here.
Environment setup:
- 1-Click Launch (Browser): Open in GitHub CodespacesOpen in Google Cloud Shell
- Local machine: If you're continuing the course in sequence,
cdinto theadk-trainingproject you created in Module 2 and skip the block below -- your environment and dependencies already carry forward. If you're starting fresh at this module, create that project first:uv init adk-training --python 3.10 && cd adk-training
uv add "google-adk>=2.1.0" python-dotenv- DevContainer / Codespaces (Alternative): If you opened this repository in a DevContainer or GitHub Codespaces, Python 3.11,
uv,gcloud, and all core ADK dependencies are pre-installed in your container environment.
Prerequisitesโ
- Python 3.10+ and
uvinstalled. - Either a Google Cloud Project authenticated via
gcloud auth application-default login(recommended for Part 6 & Part 7) or aGEMINI_API_KEYfrom Google AI Studio for local smoke testing.
Step 1: Sync Skills, Scaffold support-ops-agent & Author .agents-cli-spec.mdโ
-
Install (or verify)
google-agents-cli(~= 1.10.0) and sync coding-agent skills:uv tool install google-agents-cli
agents-cli --version
# Preview detected coding agents, then sync the 7 google-agents-cli-* skills
agents-cli setup --dry-run
agents-cli setup --skip-auth -
Scaffold
support-ops-agentin--prototypemode from your parent workspace: Navigate to youradk-trainingworkspace folder. CRITICAL: Do NOT runmkdir support-ops-agentfirst! Letagents-cli createcreate the directory (<= 26lowercase[a-z0-9-]characters):cd /path/to/your/adk-training
agents-cli create support-ops-agent \
--agent adk \
--prototype \
--agent-guidance-filename GEMINI.md \
--skip-checks -y
cd support-ops-agent
agents-cli infoInspect
agents-cli-manifest.yamland confirm top-levelagent_directory: "app"and nestedcreate_params.root_agent_name: "support_ops_agent". -
Configure
.envinsupport-ops-agent/.env: Use either your Google Cloud project (recommended across Part 6) or a Google AI Studio key:# Option A (Recommended for Part 6 & Part 7): Gemini platform on Google Cloud
GOOGLE_GENAI_USE_ENTERPRISE=true
GOOGLE_CLOUD_PROJECT=YOUR_PROJECT_ID
GOOGLE_CLOUD_LOCATION=global
# Option B (Local AI Studio key): comment out the 3 lines above and uncomment:
# GEMINI_API_KEY=YOUR_GEMINI_API_KEY -
Draft your Phase 0 Specification in
support-ops-agent/.agents-cli-spec.md: Create.agents-cli-spec.mdat the root ofsupport-ops-agent/using the starter skeleton below and complete the# TODOsections so your mission, tools, state keys, constraints, and evaluation success criteria are pinned before coding:# Agent Spec: Support Operations Agent (`support-ops-agent`)
## Overview
<!-- TODO: Describe the core mission of support_ops_agent (triaging support tickets,
checking customer-tier SLA response targets, and escalating P1 incidents). -->
## Language & Runtime Stack
- Language: `python` (`google-adk >= 2.1.0`, `google-agents-cli ~= 1.10.0`)
- Model: `gemini-3.8-flash`
- Serving Surface: ADK SSE (`/run_sse`) + built-in A2A (`/a2a/app`)
## Session & User State Keys
<!-- TODO: Document the 3 state keys managed across turns:
1. `user:customer_tier` (default `"standard"`, updated on ticket lookup)
2. `active_ticket_id` (most recently inspected normalized ticket ID)
3. `escalated_tickets` (deduplicated list of escalated ticket IDs in session) -->
## Tools Required
<!-- TODO: Specify `lookup_ticket`, `check_sla_policy`, and `escalate_ticket`
with their inputs and expected dictionary return contracts. -->
## Constraints, Safety Rules & Non-Goals
<!-- TODO: List explicit guardrails (never invent ticket data or SLA numbers;
never escalate unknown tickets) and non-goals (no direct billing refunds or DB deletes). -->
## Success Criteria
<!-- TODO: Define 3 measurable behaviors we will grade in Module 30.2:
1. P1 enterprise ticket triage + automatic escalation to `24/7 P1 SRE Oncall`
2. Standard ticket lookup + exact SLA citation without unnecessary escalation
3. Graceful handling of unknown ticket IDs listing `available_sample_tickets` -->
## Reference Samples
- `core/python/long-horizon-harness` โ A2A interoperability & structured tool guardrails
- `core/python/rag-agent-search` โ future runbook retrieval recipe (if KB search is added later)
Step 2: Implement Stateful support_ops_agent in app/agent.pyโ
Open support-ops-agent/app/agent.py and replace the generated starter template with the challenge skeleton below. Complete # TODO 1 through # TODO 6 while strictly preserving MODEL = "gemini-3.8-flash", Agent(name="support_ops_agent"), and App(root_agent=root_agent, name="app"):
"""
Enterprise Support Operations Agent โ Canonical Part 6 End-to-End Agent (`agents-cli`).
Built with Google ADK 2.0 (`gemini-3.8-flash`), stateful tools, and built-in A2A serving.
"""
from typing import Any
from google.adk.agents import Agent
from google.adk.agents.callback_context import CallbackContext
from google.adk.apps import App
from google.adk.models import Gemini
from google.adk.tools.tool_context import ToolContext
from google.genai import types
MODEL = "gemini-3.8-flash"
TICKET_DB: dict[str, dict[str, Any]] = {
"TCK-1042": {
"customer": "Acme Cloud Robotics",
"tier": "enterprise",
"severity": "P1",
"ticket_status": "open",
"summary": "Production payment webhook returning HTTP 503 timeouts in eu-west1.",
},
"TCK-2088": {
"customer": "Northwind Retail",
"tier": "standard",
"severity": "P3",
"ticket_status": "investigating",
"summary": "CSV invoice export omits localized tax column.",
},
}
SLA_POLICIES: dict[str, dict[str, str]] = {
"enterprise": {
"P1_response": "15 minutes",
"P2_response": "1 hour",
"P3_response": "4 hours",
"dedicated_oncall": "Yes (24/7 SRE pager)",
},
"standard": {
"P1_response": "2 hours",
"P2_response": "8 hours",
"P3_response": "24 business hours",
"dedicated_oncall": "No (business-hours queue)",
},
}
def initialize_support_state(callback_context: CallbackContext) -> None:
"""Initializes default session and user state keys before the first turn."""
# TODO 1: Initialize `callback_context.state["user:customer_tier"] = "standard"`
# and `callback_context.state["escalated_tickets"] = []` ONLY if each key
# is not already present in `callback_context.state`.
pass
def lookup_ticket(ticket_id: str, tool_context: ToolContext) -> dict[str, Any]:
"""Looks up an enterprise support ticket by ID and syncs customer tier into state.
Args:
ticket_id: Ticket identifier such as 'TCK-1042' or 'TCK-2088'.
"""
norm_id = ticket_id.strip().upper()
# TODO 2: Look up `norm_id` in `TICKET_DB`.
# - If not found, return a dict with `"status": "not_found"`, `"ticket_id": norm_id`,
# `"available_sample_tickets": sorted(TICKET_DB.keys())`, and a clear `"message"`.
# - If found, store `record["tier"]` in `tool_context.state["user:customer_tier"]`,
# store `norm_id` in `tool_context.state["active_ticket_id"]`, and return
# `{"status": "found", "ticket_id": norm_id, **record}`.
pass
def check_sla_policy(tier: str) -> dict[str, Any]:
"""Returns response-time SLA targets for a customer tier ('enterprise' or 'standard').
Args:
tier: Customer support tier ('enterprise' or 'standard').
"""
norm_tier = tier.strip().lower()
# TODO 3: Look up `norm_tier` in `SLA_POLICIES`.
# - If missing, return `{"status": "error", "message": ...}` listing valid tiers.
# - If found, return `{"status": "success", "tier": norm_tier, "sla_targets": policy}`.
pass
def escalate_ticket(
ticket_id: str,
reason: str,
tool_context: ToolContext,
) -> dict[str, Any]:
"""Escalates a high-severity support ticket to the incident engineering queue.
Args:
ticket_id: Ticket identifier to escalate (e.g., 'TCK-1042').
reason: Concise technical justification for the escalation.
"""
norm_id = ticket_id.strip().upper()
# TODO 4:
# 1. If `norm_id` is not in `TICKET_DB`, return `{"status": "error", "message": ...}`.
# 2. Read `escalated_tickets` from `tool_context.state`, append `norm_id` if not already
# present, and write the updated list back to `tool_context.state["escalated_tickets"]`.
# 3. Route `"enterprise"` tier tickets to `"24/7 P1 SRE Oncall"` and all other tiers
# to `"Tier-2 Engineering Queue"`.
# 4. Return a dict with `"status": "escalated"`, `"ticket_id": norm_id`,
# `"assigned_queue"`, `"reason": reason.strip()`, and `"session_escalated_tickets"`.
pass
# TODO 5: Instantiate `root_agent = Agent(...)` with:
# - `name="support_ops_agent"` (MUST match `create_params.root_agent_name` in `agents-cli-manifest.yaml`)
# - `description="Triages enterprise support tickets, verifies SLA policies, and escalates P1 incidents."`
# - `model=Gemini(model=MODEL, retry_options=types.HttpRetryOptions(attempts=3))`
# - `before_agent_callback=initialize_support_state`
# - `instruction` referencing `{user:customer_tier?}` that directs the agent to:
# 1. Call `lookup_ticket` first whenever a ticket ID is mentioned,
# 2. Call `check_sla_policy` for the ticket's customer tier to cite exact SLA targets,
# 3. Call `escalate_ticket` automatically for P1 tickets or explicit escalation requests,
# 4. List `available_sample_tickets` helpfully if a ticket ID is not found.
# - `tools=[lookup_ticket, check_sla_policy, escalate_ticket]`
root_agent = None # Replace with Agent(...)
# TODO 6: Wrap `root_agent` in `app = App(root_agent=root_agent, name="app")`
# CRITICAL: `name="app"` MUST match `agent_directory: "app"` in `agents-cli-manifest.yaml`!
app = None # Replace with App(...)
Step 3: Lint, Multi-Turn Verbose Smoke Test, A2A Card & Upgrade Dry-Runโ
-
Sync dependencies and run the project linter:
agents-cli install
agents-cli lintFix any formatting or type issues reported by
agents-cli lintbefore continuing. -
Run a multi-turn stateful smoke test with
-v --start-server --session-id demo-1: Pass-v(--verbose) on Turn 1 to inspect the raw ADK JSON event stream (lookup_ticketโcheck_sla_policyโescalate_ticket), and keep the local server alive with--start-serverso Turn 2 reuses the in-memorydemo-1session:# Turn 1: Triage P1 ticket TCK-1042 with verbose event output and persistent server
agents-cli run "Investigate ticket TCK-1042 and check its SLA." \
-v --start-server --session-id demo-1
# Turn 2: Confirm session & user state persisted across invocations
agents-cli run "Which customer tier is stored in my profile, and which tickets were escalated in this session?" \
--session-id demo-1 -
Verify the built-in A2A
AgentCardwhile the local server is running: Because--start-serverkeepsapp/fast_api_app.pylistening on port8000, query the auto-generated A2A discovery endpoint before stopping the server:curl -s http://127.0.0.1:8000/a2a/app/.well-known/agent-card.json | python3 -m json.toolConfirm the JSON payload advertises
"name": "support_ops_agent","streaming": true, and the JSON-RPC/a2a/appinterface โ with zero hand-written A2A code! Now stop the background server cleanly:agents-cli run "Stop" --stop-server -
Preview non-destructive template drift maintenance (
scaffold upgrade --dry-run):agents-cli scaffold upgrade --dry-runObserve how
agents-clicomparesacli_versioninagents-cli-manifest.yamlagainst the installed CLI template using a 3-way merge without touchingapp/agent.pyor.agents-cli-spec.md.(Optional: Run
agents-cli playgroundto interact withsupport_ops_agentvisually in the browser, then pressCtrl+C.)
Self-Reflection Questionsโ
- Why did
agents-cli v1.10retire--datastoreand--agent agentic_ragin favor of sparse-cloning reference recipes (AGENTS.md) during Phase 1 while scaffolding--agent adk --prototype? - What happens at runtime if you set
App(root_agent=root_agent, name="support_ops_agent")whileagent_directoryinagents-cli-manifest.yamlis"app"? - Why should
tests/unit/only test deterministic Python helpers (such as ticket ID normalization) rather than asserting on specific words ingemini-3.8-flashresponses?
๐ Reference Solution Vaultโ
Official Solution Vault โ Module 30.1
Locked Challenge โ Active Pedagogical Socratic Gate