Skip to main content

Module 30.3: CLI Extensions, Polyglot Templates & GitOps CI/CD

Theory​

CLI Extensions, Polyglot Templates & GitOps CI/CD Architecture (Light) CLI Extensions, Polyglot Templates & GitOps CI/CD Architecture (Dark) 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:

  1. CLI Command Governance (agents-cli-extension/v1alpha1): Add organization-specific commands (such as agents-cli check-gate or agents-cli sbom-audit) and transparently wrap built-in commands like agents-cli deploy so compliance and evaluation gates execute automatically before any container is rolled out.
  2. 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.
  3. In-Place Promotion & Two-Tier GitOps CI/CD: Upgrade a validated --prototype agent in place via agents-cli scaffold enhanceβ€”preserving app/agent.py and .env untouchedβ€”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:

PriorityScopeManifest & Storage LocationHow 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.
2User 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 CLIBundled inside google-agents-cliDefault 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. Running agents-cli extension list or agents-cli info prints 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-cli applies a deterministic first-wins rule, logs a warning, and records the collision in agents-cli info.
  • Immutable SHA pinning & team skills: Running agents-cli extension add acme/agentops-extensions#release-gate --ref v1.2.0 resolves v1.2.0 to an exact Git commit sha, records source / ref / sha in agents-cli-extensions.yaml (kept separate from agents-cli-manifest.yaml so extension updates never touch scaffold metadata), vendors the code under extensions/, and syncs any bundled skills: into .agents/skills/. Fresh checkouts and offline CI jobs re-materialize pinned copies via agents-cli install without 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: warn vs error): Always declare a requires.agents_cli range matching your tested CLI version (>=1.10,<2). In warn mode, an out-of-range CLI prints a warning and still runs the extension. In error mode, if a developer upgrades agents-cli outside the supported range, agents-cli blocks the overridden command with remediation instructions rather than silently falling back to the built-in commandβ€”preventing an unguarded deploy from 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). If commands.add names an existing built-in command like deploy or lint, agents-cli refuses to register it and warns you to use commands.override instead.
  • commands.override (Wrapping Leaf & Dotted Subcommands): Intercepts an existing leaf command (deploy) or single-level dotted subcommand (eval.generate). agents-cli also automatically mirrors overrides across registered command aliases (for example, overriding scaffold.create also intercepts the top-level create alias) and honors overrides during internal cross-calls (for example, agents-cli eval run dispatches to an active eval.generate override).
  • Why Overriding a Command Group (e.g., eval or scaffold) Is Rejected: Built-in groups like eval are Click Group routers housing multiple independent subcommands (eval generate, eval grade, eval compare, eval analyze, eval optimize, eval dataset). Allowing an extension to override eval as a whole would wipe out the entire subcommand tree and break every sibling command. Therefore, agents-cli rejects 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, and extension.update are 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:

  1. No-Shell argv Vector (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 the argv vector with shell=False, eliminating shell metacharacter injection and ensuring cross-platform portability across macOS, Linux, and Windows.
  2. Working Directory & Path Expansion: agents-cli executes the child process with cwd set to the project root (or the caller's working directory when invoked outside a project), automatically resolves relative script paths inside run: 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 caller cwd.
    • AGENTS_CLI_DISABLE_OVERRIDES=1: Automatic re-entrancy guard preventing infinite recursion.
  3. Loop Prevention via AGENTS_CLI_DISABLE_OVERRIDES=1: Suppose your commands.override.deploy script validates the latest evaluation scorecard and then runs agents-cli deploy "$@". Without a guard, that inner agents-cli deploy call would trigger your deploy override again in an infinite fork loop! Because agents-cli automatically exports AGENTS_CLI_DISABLE_OVERRIDES=1 into the override child process, the inner agents-cli deploy call sees AGENTS_CLI_DISABLE_OVERRIDES=1, skips extension loading completely, and delegates cleanly to the real built-in deploy command:

(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:

DimensionPython ADK (--agent adk)Go ADK (--agent adk_go)
Scaffold Commandagents-cli create my-py-agent --agent adk --prototypeagents-cli create my-go-agent --agent adk_go --prototype
Agent Entrypointapp/agent.py (root_agent + App(name="app", ...))app/agent.go (NewRootAgent(ctx) (agent.Agent, error) via llmagent.New)
HTTP & A2A Launcherapp/fast_api_app.py + app/app_utils/a2a.py (Uvicorn/FastAPI)main.go (universal.NewLauncher + a2a.NewLauncher() + -path_prefix /) & appurl.go
Telemetry Wiringget_fast_api_app(otel_to_cloud=True)observability.go (OpenTelemetry spans & Cloud Trace exporter)
Container Builduv sync --frozen Python slim image (uv.lock)Multi-stage Go build compiling a static native binary (go.mod / go.sum)
Tests & Load Suitepytest (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 atop empty_py), the template includes a project-scoped agents-cli-extension.yaml that overrides framework-specific hooks like eval.generate while reusing agents-cli's Terraform, CI/CD, and deploy machinery unchanged.
  • --base-template (-bt): Supplies the foundational language/infrastructure layer (adk, adk_go, empty_py, empty_go) underneath a remote --agent template so organization authors only maintain their app/ 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:

Capabilitydeployment/terraform/single-project/
(agents-cli infra single-project)
deployment/terraform/cicd/
(agents-cli infra cicd)
Target Use CaseOptional 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 Modeagents-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)
AuthenticationDeveloper'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 Sizingagents-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/):

  1. Stage 1 β€” Pull Request CI (pr_checks.yaml): Triggered on every PR targeting main. Runs uv sync --frozen, linting, unit/integration tests, and evaluation checks before merge is permitted.
  2. Stage 2 β€” Automated Staging CD + Load Testing (staging.yaml): Triggered automatically on merge to main when watched paths change (app/**, tests/**, deployment/**, uv.lock for Python; app/**, e2e/**, deployment/**, go.mod, go.sum, main.go, Dockerfile for Go). cicd_runner_sa builds 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.
  3. Stage 3 β€” Gated Production Rollout (deploy-to-prod.yaml): Triggered via workflow_run only after Staging CD + load tests succeed. Pauses at a manual approval gate (GitHub production Environment protection rules or gcloud builds approve) before promoting the exact same immutable container digest into the Production project running as Production's least-privilege app_sa.
🎯 Knowledge CheckSelect Best Answer

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): Drop agents-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 via agents-cli extension add <org>/<repo> --ref <tag>.
  • Safe Command Contracts: Use commands.add for new commands (protected against shadowing built-ins) and commands.override for 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 direct argv list without a shell (["uv", "run", "python", ...]) and automatically sets AGENTS_CLI_DISABLE_OVERRIDES=1 and AGENTS_CLI_EXTENSION_DIR so wrapper scripts can inspect artifacts/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 with agents-cli scaffold enhance ., and graduate from single-project previews to keyless WIF Staging β†’ Locust load test β†’ manual-approval Production pipelines (agents-cli infra cicd) separating cicd_runner_sa from runtime app_sa.
πŸ“–

30.3: CLI Extensions & GitOps CI/CD(Theory & Overview)

Part 6: AgentOps & Google Agents CLI β€’ Module 30.3

Overall Course Progress:
0%(0/98)
Next Step: Challenge Lab πŸ§ͺ β†’