Inspiration

Production AI agents quietly burn money on economically irrational execution: the same external search repeated on every ticket, an overly too expensive model answering trivial questions, a verification loop that re-queries five times. The bill grows, and nobody can point at where (or stop it) without an engineering project. Observability tools show you the waste after the fact and leave the fix to your engineers. We wanted an agent that doesn't just watch the spend, but acts on it the moment it happens and proves it didn't break anything.

What it does

Spend Governor is AI Runtime FinOps — it governs the spend of a fleet of other AI agents in two planes:

  • Learning plane: Reads the observed agents' OTEL traces from Arize/Phoenix, attaches LLM + tool cost, aggregates to per-agent unit economics, and detects economically irrational patterns (redundant retrieval, runaway loops, unnecessarily powerful models).
  • Enforcement plane: A thin inline wrapper the agents' tool/LLM traffic flows through. The Governor applies optimizations on live traffic. It serves a semantically equivalent cache for redundant calls, caps tool loops, suppresses redundant LLM calls, and routes simple requests to a cheaper model. Then, it re-measures from the traces to prove the cost fell while quality held.

In the live cockpit, the Governor sweeps a fleet of four agents on a disclosed, time-compressed clock. It auto-applies the safe fixes (caching, call capping) and you watch $/message step down on the value spine. It delegates risky decisions (model routing) to you, since routing can degrade quality. The Governor proves whether it does with a real neutral-judge eval panel (gemini-2.5-pro, three lenses, majority vote). You gather the proof yourself via a debugger, where you can replay conversations in a safe lab environment before committing to a decision (switch to a cheaper model, or not).

The headline — Ask the Governor: click any agent and the Governor (a Google ADK agent with the Arize Phoenix MCP server registered as a tool) introspects its own operational data at runtime — it calls get-trace live, pulls a real trace, and explains the waste grounded in the actual spans, with trace/span ids that link straight into Phoenix. The agentic loop (plan → call MCP → explain) is readily available on the UI.

How we built it

  • Google Cloud Agent Builder — Google ADK. Both the Governor and the observed fleet are Google ADK agents — the code-owned agent runtime the Arize track requires ("…Google ADK… the visual Agent Builder alone is not supported for tracing integration"). We deploy on Cloud Run for exactly that reason.
  • Gemini: gemini-2.5-flash (the live MCP chat + the observed fleet), gemini-2.5-pro (the neutral eval judge), and Gemini embeddings (the semantic cache).
  • Arize / Phoenix: OTEL traces via OpenInference auto-instrumentation for ADK, sent to Phoenix Cloud. Two load-bearing paths: the learning pipeline reads traces in bulk via the Phoenix SDK/GraphQL; the Governor agent introspects them at runtime via the Phoenix MCP server.
  • FastAPI + SQLite (inline gateway, control-plane API + SSE, cost/policy store), React (Vite) (the live cockpit), all shipped as a single Google Cloud Run service.

All traces are synthetic. They've been generated by the observed agent fleet. No real user or customer data is used anywhere.

Challenges we ran into

  • Making MCP load-bearing, not decorative. Reading Phoenix with a plain SDK call is easy. But we wanted the agent itself to introspect at runtime, so the ADK agent calls the Phoenix MCP server in its tool loop — on screen. Getting it to stream tool-calls and a grounded answer in a few seconds took several passes (disabling adaptive thinking, a single trace fetch, token streaming).
  • Phoenix MCP on a read-only filesystem. The MCP server runs via npx, which needs a writable cache, but Cloud Run's filesystem is read-only. We bake the phoenix-mcp binary into the image and invoke it directly.
  • Proving savings honestly. Every dollar on the dashboard must be re-derivable from the customer's own Phoenix traces, so we reconciled our local cost math against Phoenix's native cost to the cent — including the cached-input rate, which the instrumentor doesn't surface by default.
  • Shipping to a locked-down org. A Domain-Restricted-Sharing policy blocked public (allUsers) access, and a free-trial billing account wouldn't enable the Gemini paid tier — both surfaced only at deploy time.

Accomplishments that we're proud of

  • MCP that actually carries weight. The Governor introspects its own operational data at runtime. It calls the Arize Phoenix MCP server inside its ADK tool loop, pulls a real trace, and grounds its answer in the spans, live and on screen. The agentic loop (plan → call MCP → explain) is the product, not a buried SDK read.
  • Every number is provable. Savings aren't estimated. Instead, they're measured before/after from the customer's own Phoenix traces, and we reconciled our cost math against Phoenix's native cost to the cent (cached-input rate included). The claim survives an audit.
  • We show the limit, not just the win. A neutral-judge eval panel (gemini-2.5-pro, three lenses, majority vote) catches that economy routing genuinely degrades quality — so the system declines to auto-apply it and lets you revert. Honest cost optimization, not a vibe check.
  • Autonomous where it's safe, human where it's risky. The Governor applies the output-preserving fixes (cache, cap) on its own and escalates the answer-affecting ones for approval. This is a real human-in-the-loop control plane, not a black box.
  • Real, end-to-end, one service. Real ADK agents, real OTEL traces, real eval verdicts, real measured savings. The whole fleet + cockpit + live MCP deploys as a single Cloud Run service. The only thing scripted is when each problem surfaces, and the clock says so.

What we learned

  • Cache and cap are free wins. Eliminating a redundant web_search loop or capping a runaway one cuts cost with quality held by construction; the Governor applies these autonomously.
  • Economy routing is not free. Measured by the neutral judge, routing the over-powered agent to a cheaper model genuinely degraded answer quality. The honest move is to surface that, decline to auto-apply, and let the operator revert. Showing the limit is the point.
  • Auditability changes the conversation. When every saving is measured before/after from the traces (not estimated) and every intervention is tagged in the trace record, the claim survives scrutiny. At ~4M messages/month the baseline spend is on the order of $64K; the governed deltas are read straight off Phoenix.

What's next for Spend Governor

Close the quality-measurement loop further (continuous eval on live traffic), broaden the policy library, and create the gateway to more frameworks.

Built With

Share this project:

Updates