Skip to content

feat: add governance plugin (budget, circuit breaker, degradation)#100

Open
amabito wants to merge 2 commits intogoogle:mainfrom
amabito:feat/governance-plugin
Open

feat: add governance plugin (budget, circuit breaker, degradation)#100
amabito wants to merge 2 commits intogoogle:mainfrom
amabito:feat/governance-plugin

Conversation

@amabito
Copy link

@amabito amabito commented Mar 15, 2026

PR Title

feat: add governance plugin (budget, circuit breaker, degradation)

PR Description

Why are these changes needed?

ADK has max_llm_calls in RunConfig and callback hooks for custom logic, but nothing for budget limits or failure isolation. In multi-agent workflows there's no way to cap spending per agent, isolate one that keeps failing, or switch to a cheaper model when budget runs low.

This adds a governance module under adk_community with a VeronicaGovernancePlugin that covers these cases.

What this adds

src/google/adk_community/governance/ -- a BasePlugin implementation with:

  • Budget enforcement: per-agent and org-level cost tracking via before_model_callback / after_model_callback. Blocks calls that would exceed limits.
  • Circuit breaker: consecutive failure tracking per agent. After N failures the agent is isolated (OPEN). After a timeout, one probe request is allowed (HALF_OPEN).
  • Tool policy: block or allowlist specific tools via config.
  • Degradation: near the budget limit (e.g. 80%), switches to a cheaper model and optionally disables expensive tools. Logged on trigger and in the after-run summary.

Config is a single GovernanceConfig Pydantic model, registered on the Runner via plugins=[...].

Related issue number

N/A (new contribution)

Design decisions

  • No extra deps. Just needs google-adk.
  • Category, not product. Placed under governance/ (alongside memory/ and sessions/) rather than plugins/veronica/ -- leaves room for other impls.
  • Ported from veronica-core. Budget, circuit breaker, and degradation patterns adapted to ADK callbacks.

Files

src/google/adk_community/governance/
  __init__.py
  veronica_governance_plugin.py    # main plugin (BasePlugin subclass)
  _budget.py                       # per-agent + org budget tracker
  _circuit_breaker.py              # per-agent failure isolation
  _policy.py                       # tool block/allow list
  _degradation.py                  # model fallback + tool disabling

tests/unittests/governance/
  test_veronica_governance_plugin.py  # 29 integration tests
  test_budget.py                      # 7 unit tests
  test_circuit_breaker.py             # 7 unit tests
  test_policy.py                      # 6 unit tests
  test_degradation.py                 # 7 unit tests

contributing/samples/governance/
  main.py                          # multi-agent example
  README.md

Checks

  • I have added tests for the changes.
  • I have updated or added documentation (plugin README + sample).
  • pytest ./tests/unittests/governance passes (56/56).

@google-cla
Copy link

google-cla bot commented Mar 15, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the ADK's capabilities by introducing a comprehensive governance plugin. This plugin addresses critical needs in multi-agent systems, such as cost control, fault tolerance, and resource optimization. By providing configurable budget limits, a circuit breaker for agent stability, tool usage policies, and intelligent model degradation, it empowers developers to build more resilient and cost-effective AI applications.

Highlights

  • New Governance Plugin: Introduced a VeronicaGovernancePlugin to the ADK community module, providing robust governance features for multi-agent workflows.
  • Budget Enforcement: Implemented per-agent and organizational budget tracking, blocking model calls that would exceed predefined cost limits.
  • Circuit Breaker: Added a circuit breaker mechanism to isolate agents after a configurable number of consecutive failures, with a half-open state for recovery probes.
  • Tool Policy: Enabled configuration of tool usage policies, allowing specific tools to be blocked or allowlisted.
  • Model Degradation: Integrated logic to automatically switch to a cheaper fallback model and optionally disable expensive tools when budget utilization approaches a set threshold.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • contributing/samples/governance/README.md
    • Added a new README file detailing the governance plugin example.
  • contributing/samples/governance/main.py
    • Added a new multi-agent example demonstrating the usage and features of the governance plugin.
  • src/google/adk_community/init.py
    • Imported the new 'governance' module to make it accessible within the ADK community package.
  • src/google/adk_community/governance/init.py
    • Added a new initialization file for the governance module, exposing key classes.
  • src/google/adk_community/governance/_budget.py
    • Added a new module for BudgetTracker and BudgetSnapshot to manage cost tracking and limits.
  • src/google/adk_community/governance/_circuit_breaker.py
    • Added a new module for CircuitBreaker and CircuitState to implement failure isolation logic.
  • src/google/adk_community/governance/_degradation.py
    • Added a new module for DegradationManager and DegradationEvent to handle model degradation and tool disabling.
  • src/google/adk_community/governance/_policy.py
    • Added a new module for ToolPolicy to enforce rules on tool usage.
  • src/google/adk_community/governance/veronica_governance_plugin.py
    • Added the core VeronicaGovernancePlugin implementation, integrating all governance functionalities.
  • tests/unittests/governance/init.py
    • Added a new initialization file for the governance unit tests.
  • tests/unittests/governance/test_budget.py
    • Added unit tests for the BudgetTracker class.
  • tests/unittests/governance/test_circuit_breaker.py
    • Added unit tests for the CircuitBreaker class.
  • tests/unittests/governance/test_degradation.py
    • Added unit tests for the DegradationManager class.
  • tests/unittests/governance/test_policy.py
    • Added unit tests for the ToolPolicy class.
  • tests/unittests/governance/test_veronica_governance_plugin.py
    • Added comprehensive unit tests for the VeronicaGovernancePlugin.
Activity
  • Added tests for all new governance features, ensuring functionality and reliability.
  • Updated documentation by adding a README for the governance plugin example and a multi-agent sample.
  • Confirmed that all 56 unit tests for the governance module passed successfully.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive governance plugin with features for budget control, circuit breaking, tool policies, and service degradation. The implementation is well-structured across several modules and includes a thorough set of unit tests, which is excellent. My review focuses on minor code cleanup and style consistency. I've identified a few unused imports and one import that could be moved to follow PEP 8 guidelines. Overall, this is a high-quality contribution.

user_id="demo_user",
)

from google.genai import types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

According to PEP 8, imports should be at the top of the file. Please move this import to the top-level import block to improve code readability and organization.

from __future__ import annotations

from dataclasses import dataclass
from dataclasses import field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The field function from dataclasses is imported but not used in this file. It should be removed to keep the code clean.

from __future__ import annotations

from dataclasses import dataclass
from dataclasses import field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The field function from dataclasses is imported but not used in this file. It should be removed to keep the code clean.

from typing import Any
from typing import Optional

from google.adk.agents.base_agent import BaseAgent
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The BaseAgent class is imported but not used in this file. It should be removed to keep the code clean.

amabito added 2 commits March 15, 2026 10:54
Adds src/google/adk_community/governance/ with VeronicaGovernancePlugin,
a BasePlugin that enforces per-agent and org-level budget limits, isolates
failing agents via circuit breaker, blocks disallowed tools, and degrades
to cheaper models when budget runs low.

56 tests, isort + pyink formatted, no extra dependencies.
- Move google.genai types import to top of main.py (PEP 8)
- Remove unused import: dataclasses.field in _budget.py, _degradation.py
- Remove unused import: BaseAgent in veronica_governance_plugin.py
@amabito amabito force-pushed the feat/governance-plugin branch from f0788a1 to 0a1573a Compare March 15, 2026 01:54
@amabito
Copy link
Author

amabito commented Mar 15, 2026

Addressed all 4 review comments in 0a1573a: moved import to top-level, removed unused field and BaseAgent imports.

@amabito
Copy link
Author

amabito commented Mar 15, 2026

Hey @Jacksunwei @hangfei -- noticed there are ~20 open community PRs with no reviews. Is this repo still actively maintained? Happy to help with reviews if that's useful. Just want to know if it's worth iterating on this PR or if the process has moved somewhere else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant