Module 30.3: CLI Extensions, Polyglot Templates & GitOps CI/CD
Theoryβ
Figure: Enterprise governance and delivery pipeline combining agents-cli-extension/v1alpha1 command interception, polyglot scaffolding (adk / adk_go / remote templates), and two-tier GitOps CI/CD promotion.
Why Governance Must Live Inside the CLI Surfaceβ
In Module 30.2, you learned an essential operational nuance of agents-cli eval: agents-cli eval run and agents-cli eval grade exit with code 0 whenever the evaluation pipeline finishes, even if an agent's quality rubric score drops to 1.5 / 5.0. If a developer or a CI job runs agents-cli deploy without inspecting artifacts/grade_results/, a regressed prompt can reach cloud infrastructure unchallenged.
Platform engineering teams need three capabilities to standardize AgentOps across dozens of repositories without maintaining brittle fork scripts:
- CLI Command Governance (
agents-cli-extension/v1alpha1): Add organization-specific commands (such asagents-cli check-gateoragents-cli sbom-audit) and transparently wrap built-in commands likeagents-cli deployso compliance and evaluation gates execute automatically before any container is rolled out. - Polyglot & Custom Template Standardization: Scaffold both Python ADK (
--agent adk), Go ADK (--agent adk_go), and custom organization or third-party framework templates (local@,adk@,github.com/org/repo/path@ref,--base-template) under one unified operational contract. - In-Place Promotion & Two-Tier GitOps CI/CD: Upgrade a validated
--prototypeagent in place viaagents-cli scaffold enhanceβpreservingapp/agent.pyand.envuntouchedβwhile layering keyless Workload Identity Federation (wif.tf), Staging load tests, and manual Production approval gates.
Deep Dive: The agents-cli-extension/v1alpha1 Extension Systemβ
An agents-cli extension is a directory containing an agents-cli-extension.yaml manifest that contributes new subcommands or wraps existing built-in commands. Extensions use the exact same YAML format whether authored ad-hoc at the root of a single project or published in a central Git repository for an entire engineering organization.
1. Precedence, Scope Hierarchy & Pinningβ
When agents-cli starts up, it discovers extensions across scopes and merges their command contributions in strict priority order:
| Priority | Scope | Manifest & Storage Location | How It Is Activated & Shared |
|---|---|---|---|
| 1 (Highest) | Project Scope | ./agents-cli-extension.yaml (inline)./agents-cli-extensions.yaml + ./extensions/<name>/ (pinned) | Auto-loaded for the repository in cwd. Committed to Git so every teammate and CI runner enforces the exact same gates automatically. |
| 2 | User Scope (--global) | ~/.config/agents-cli/agents-cli-extensions.yaml~/.config/agents-cli/extensions/<name>/ | Installed via agents-cli extension add <ref> --global. Applies across all projects on your workstation (and even outside any project). |
| 3 (Lowest) | Built-in CLI | Bundled inside google-agents-cli | Default implementation executed when no active extension overrides the target command (or when overrides are bypassed). |
Key lifecycle mechanics for enterprise teams:
- Cross-scope resolution: If both User scope and Project scope define the same command (for example,
deploy), Project scope always wins. Runningagents-cli extension listoragents-cli infoprints every active extension, its scope, and any shadowed conflicts. - Same-scope conflict protection: If two extensions within the same scope claim the same command,
agents-cliapplies a deterministic first-wins rule, logs a warning, and records the collision inagents-cli info. - Immutable SHA pinning & team skills: Running
agents-cli extension add acme/agentops-extensions#release-gate --ref v1.2.0resolvesv1.2.0to an exact Git commitsha, recordssource/ref/shainagents-cli-extensions.yaml(kept separate fromagents-cli-manifest.yamlso extension updates never touch scaffold metadata), vendors the code underextensions/, and syncs any bundledskills:into.agents/skills/. Fresh checkouts and offline CI jobs re-materialize pinned copies viaagents-cli installwithout advancing the pin.
2. Strict Manifest Anatomy (schema: agents-cli-extension/v1alpha1)β
The extension loader validates agents-cli-extension.yaml using a strict Pydantic model (extra="forbid"). Any unknown or misspelled top-level keyβsuch as writing Kubernetes-style apiVersion: instead of schema:βfails loudly instead of silently doing nothing:
# yaml-language-server: $schema=https://raw.githubusercontent.com/google/agents-cli/main/schemas/agents-cli-extension-v1alpha1.schema.json
schema: agents-cli-extension/v1alpha1
name: enterprise-release-gate
description: Enforces minimum evaluation rubric scores before permitting cloud deploy.
requires:
agents_cli: ">=1.10,<2"
on_incompatible: error # fail-closed: error | warn
commands:
add:
check-gate:
run: ["uv", "run", "python", "scripts/verify_eval_gate.py"]
description: Verify the latest evaluation scorecard in artifacts/grade_results/.
override:
deploy:
run: ["uv", "run", "python", "scripts/verify_eval_gate.py", "--delegate-deploy"]
description: Validate evaluation scorecard before delegating to built-in deploy.
Compatibility Enforcement (
on_incompatible: warnvserror): Always declare arequires.agents_clirange matching your tested CLI version (>=1.10,<2). Inwarnmode, an out-of-range CLI prints a warning and still runs the extension. Inerrormode, if a developer upgradesagents-clioutside the supported range,agents-cliblocks the overridden command with remediation instructions rather than silently falling back to the built-in commandβpreventing an unguardeddeployfrom bypassing a mandatory security gate!
3. commands.add vs commands.override (And Why Group Overrides Are Rejected)β
agents-cli separates command registration into two explicit contracts so extensions never accidentally clobber CLI functionality:
commands.add(Brand-New Commands + Collision Protection): Registers a new top-level command (e.g.,check-gateβagents-cli check-gate) or a new single-level subcommand under an existing group (e.g.,eval.auditβagents-cli eval audit). Ifcommands.addnames an existing built-in command likedeployorlint,agents-clirefuses to register it and warns you to usecommands.overrideinstead.commands.override(Wrapping Leaf & Dotted Subcommands): Intercepts an existing leaf command (deploy) or single-level dotted subcommand (eval.generate).agents-clialso automatically mirrors overrides across registered command aliases (for example, overridingscaffold.createalso intercepts the top-levelcreatealias) and honors overrides during internal cross-calls (for example,agents-cli eval rundispatches to an activeeval.generateoverride).- Why Overriding a Command Group (e.g.,
evalorscaffold) Is Rejected: Built-in groups likeevalare ClickGrouprouters housing multiple independent subcommands (eval generate,eval grade,eval compare,eval analyze,eval optimize,eval dataset). Allowing an extension to overrideevalas a whole would wipe out the entire subcommand tree and break every sibling command. Therefore,agents-clirejects group overrides (cannot override command group 'eval'; override a subcommand instead) so peer subcommands retain their built-in behavior. - Non-Overridable Recovery Commands:
install,extension,extension.add,extension.list,extension.remove, andextension.updateare permanently protected. Even a broken or incompatible extension can never hijack the commands used to repair or uninstall it.
4. No-Shell Execution Security & Loop Prevention (AGENTS_CLI_DISABLE_OVERRIDES=1)β
Every extension command runs under a hardened subprocess contract:
- No-Shell
argvVector (run:):run:must be a non-empty list of strings starting with an explicit executable or interpreter (such as["uv", "run", "python", "scripts/verify_eval_gate.py"]), never a shell command line (sh -c "..."). User arguments typed after the command name (such as--dry-run --project my-gcp-proj) are appended verbatim to theargvvector withshell=False, eliminating shell metacharacter injection and ensuring cross-platform portability across macOS, Linux, and Windows. - Working Directory & Path Expansion:
agents-cliexecutes the child process withcwdset to the project root (or the caller's working directory when invoked outside a project), automatically resolves relative script paths insiderun:against the extension directory, and merges two environment variables into the child's environment (os.environ):AGENTS_CLI_EXTENSION_DIR: Absolute path to the extension's root directory so wrapper scripts can reliably locate sibling helper scripts, schemas, or templates regardless of callercwd.AGENTS_CLI_DISABLE_OVERRIDES=1: Automatic re-entrancy guard preventing infinite recursion.
- Loop Prevention via
AGENTS_CLI_DISABLE_OVERRIDES=1: Suppose yourcommands.override.deployscript validates the latest evaluation scorecard and then runsagents-cli deploy "$@". Without a guard, that inneragents-cli deploycall would trigger yourdeployoverride again in an infinite fork loop! Becauseagents-cliautomatically exportsAGENTS_CLI_DISABLE_OVERRIDES=1into the override child process, the inneragents-cli deploycall seesAGENTS_CLI_DISABLE_OVERRIDES=1, skips extension loading completely, and delegates cleanly to the real built-indeploycommand:
(Tip: Humans debugging a misbehaving extension interactively can also use the same variable directly from their shellβAGENTS_CLI_DISABLE_OVERRIDES=1 agents-cli deploy --dry-runβto bypass overrides for a single invocation.)
Polyglot & Organization Template Ecosystemβ
Because every agents-cli deployment target (Agent Runtime, Cloud Run, and GKE) is container-based, your agent runtime contract is defined by HTTP/A2A and OpenTelemetry rather than a single programming language.
1. Python ADK (--agent adk) vs Go ADK (--agent adk_go)β
adk (Python, default) and adk_go (Go, google.golang.org/adk/v2) are the two first-party ADK templates shipped inside agents-cli. Both wire up gemini-3.8-flash, built-in A2A discovery (/.well-known/agent-card.json), evaluation endpoints, and Cloud Trace out of the box:
| Dimension | Python ADK (--agent adk) | Go ADK (--agent adk_go) |
|---|---|---|
| Scaffold Command | agents-cli create my-py-agent --agent adk --prototype | agents-cli create my-go-agent --agent adk_go --prototype |
| Agent Entrypoint | app/agent.py (root_agent + App(name="app", ...)) | app/agent.go (NewRootAgent(ctx) (agent.Agent, error) via llmagent.New) |
| HTTP & A2A Launcher | app/fast_api_app.py + app/app_utils/a2a.py (Uvicorn/FastAPI) | main.go (universal.NewLauncher + a2a.NewLauncher() + -path_prefix /) & appurl.go |
| Telemetry Wiring | get_fast_api_app(otel_to_cloud=True) | observability.go (OpenTelemetry spans & Cloud Trace exporter) |
| Container Build | uv sync --frozen Python slim image (uv.lock) | Multi-stage Go build compiling a static native binary (go.mod / go.sum) |
| Tests & Load Suite | pytest (tests/unit/, tests/integration/) + tests/load_test/ | go test ./... (app/agent_test.go, e2e/integration/) + e2e/load_test/ |
2. Remote, Sample & Organization Templates (adk@, local@, Git URLs, --base-template)β
Beyond the built-in templates, --agent (-a) accepts rich template references so platform teams and external ecosystems can distribute opinionated starter kits without global installation:
# 1. Official adk-samples shortcut (clones directly from google/adk-samples)
agents-cli create finance-bot --agent adk@data-science --prototype
# 2. Local organization template directory (ideal while developing custom templates)
agents-cli create internal-bot --agent local@../platform-templates/soc2-adk --prototype
# 3. Remote Git repository / subdirectory pinned to a branch, tag, or SHA
# (e.g., first-party LangChain template bundling its own agents-cli-extension.yaml!)
agents-cli create lc-support-bot \
--agent github.com/google/agents-cli/extensions/langchain/template@v1.10.0 \
--prototype
# 4. Layering a remote agent template over a specific CLI base template (--base-template / -bt)
agents-cli create custom-py-bot \
--agent github.com/acme-corp/agent-templates/triage@main \
--base-template empty_py \
--deployment-target cloud_run
- Framework templates carry their own extensions: When you scaffold from a non-ADK template such as
google/agents-cli/extensions/langchain/template@v1.10.0(or a Claude Agent SDK template built atopempty_py), the template includes a project-scopedagents-cli-extension.yamlthat overrides framework-specific hooks likeeval.generatewhile reusingagents-cli's Terraform, CI/CD, anddeploymachinery unchanged. --base-template(-bt): Supplies the foundational language/infrastructure layer (adk,adk_go,empty_py,empty_go) underneath a remote--agenttemplate so organization authors only maintain theirapp/code and delta files rather than duplicating Terraform modules.
Promoting Prototypes to Infrastructure & Two-Tier GitOps CI/CDβ
Following the Prototype-First lifecycle from Module 30.1, you start without infrastructure noise (--prototype), lock in behavior with eval in Module 30.2, attach your release gate extension, and then promote the repository in place using agents-cli scaffold enhance:
# Promote current prototype directory in place with Cloud Run + GitHub Actions CI/CD
agents-cli scaffold enhance . \
--deployment-target cloud_run \
--cicd-runner github_actions \
--skip-checks \
-y
scaffold enhance reads agents-cli-manifest.yaml, renders the selected deployment target and CI/CD runner (github_actions or google_cloud_build), and preserves your app/agent.py, .env, agents-cli-extension.yaml, and evaluation datasets untouched.
Comparing single-project vs Two-Tier cicd Infrastructureβ
Enhancing a project generates two distinct Terraform roots under deployment/terraform/. Notice that both agents-cli infra single-project and agents-cli infra cicd run terraform plan preview mode by defaultβnothing is provisioned in Google Cloud unless you explicitly pass --apply:
| Capability | deployment/terraform/single-project/( agents-cli infra single-project) | deployment/terraform/cicd/( agents-cli infra cicd) |
|---|---|---|
| Target Use Case | Optional single-project setup for dev/team sandboxes needing dedicated IAM, Secret Manager, or BigQuery/GCS telemetry buckets without CI/CD. | Production multi-environment GitOps pipeline promoting code across isolated Staging and Production GCP projects. |
| Plan / Preview Mode | agents-cli infra single-project --project <DEV_PROJECT> (default preview without --apply) | agents-cli infra cicd --staging-project <STG> --prod-project <PRD> --repository-name <REPO> (preview without --apply) |
| Authentication | Developer's ambient gcloud ADC credentials (agents-cli deploy --service-account <app_sa>). | Keyless Workload Identity Federation (wif.tf) exchanging GitHub Actions / Cloud Build OIDC tokensβzero long-lived JSON keys! |
Service Accounts (iam.tf) | Single runtime app_sa scoped to the target GCP project. | Strict privilege separation: cicd_runner_sa (build & rollout identity in CI/CD project) + isolated per-environment app_sa (Staging & Prod). |
| Cold-Start Sizing | agents-cli deploy defaults to --min-instances 0 (scale-to-zero cost savings in dev); service.tf pins min_instances = 1. | service.tf provisions warm capacity (min_instances = 1) in Staging/Prod and validates concurrency via post-deploy load tests. |
The 3-Stage GitOps Promotion Pipelineβ
Once agents-cli infra cicd --apply wires your GitHub repository variables and Workload Identity Pool, every code change flows through three automated stages (.github/workflows/ or .cloudbuild/):
- Stage 1 β Pull Request CI (
pr_checks.yaml): Triggered on every PR targetingmain. Runsuv sync --frozen, linting, unit/integration tests, and evaluation checks before merge is permitted. - Stage 2 β Automated Staging CD + Load Testing (
staging.yaml): Triggered automatically on merge tomainwhen watched paths change (app/**,tests/**,deployment/**,uv.lockfor Python;app/**,e2e/**,deployment/**,go.mod,go.sum,main.go,Dockerfilefor Go).cicd_runner_sabuilds the container image once, deploys it to the Staging GCP project, and runs Locust post-deploy load tests (tests/load_test/) against the live Staging endpoint to catch latency spikes or memory/OOM bottlenecks under concurrent load. - Stage 3 β Gated Production Rollout (
deploy-to-prod.yaml): Triggered viaworkflow_runonly after Staging CD + load tests succeed. Pauses at a manual approval gate (GitHubproductionEnvironment protection rules orgcloud builds approve) before promoting the exact same immutable container digest into the Production project running as Production's least-privilegeapp_sa.
Your platform team authors a project-scoped 'agents-cli-extension.yaml' that overrides 'deploy' with a Python script verifying evaluation scores before calling 'agents-cli deploy'. Why doesn't the inner 'agents-cli deploy' call trigger an infinite recursion loop, and why did the team override 'eval.generate' instead of 'eval' for their custom trace runner?
Key Takeawaysβ
- Zero-Fork CLI Governance (
agents-cli-extension/v1alpha1): Dropagents-cli-extension.yaml(schema: agents-cli-extension/v1alpha1) at your repo root for instant Project-scope governance (Project > User > Built-in), or share SHA-pinned extensions and.agents/skills/across repositories viaagents-cli extension add <org>/<repo> --ref <tag>. - Safe Command Contracts: Use
commands.addfor new commands (protected against shadowing built-ins) andcommands.overridefor leaf or dotted subcommands (deploy,eval.generate). Command groups (eval,scaffold) and recovery commands (install,extension.*) can never be overridden. - No-Shell Vectors &
AGENTS_CLI_DISABLE_OVERRIDES=1:run:executes a directargvlist without a shell (["uv", "run", "python", ...]) and automatically setsAGENTS_CLI_DISABLE_OVERRIDES=1andAGENTS_CLI_EXTENSION_DIRso wrapper scripts can inspectartifacts/grade_results/and delegate cleanly back to built-in commands without infinite loops. - Polyglot Templates & Two-Tier GitOps: Scaffold Python (
--agent adk), Go (--agent adk_go), or remote/org templates (adk@,local@, Git URLs,--base-template), promote prototypes in place withagents-cli scaffold enhance ., and graduate from single-project previews to keyless WIF Staging β Locust load test β manual-approval Production pipelines (agents-cli infra cicd) separatingcicd_runner_safrom runtimeapp_sa.