Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions contributing/samples/agent_governance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ An ADK plugin that enforces policy-as-code rules before tool execution using the
## Install

```bash
pip install google-adk-community agentmesh-platform
pip install google-adk-community agent-governance-toolkit-core
```

## Usage
Expand Down Expand Up @@ -57,7 +57,7 @@ contract). Allowed calls return `None`, letting the tool proceed normally.

## Fail-closed by default

If `agentmesh-platform` is not installed, the plugin raises `ImportError`
If `agent-governance-toolkit-core` is not installed, the plugin raises `ImportError`
at construction time. Pass `fail_open=True` to degrade gracefully instead
(all calls pass through with a logged warning).

Expand Down
16 changes: 8 additions & 8 deletions src/google/adk_community/plugins/agent_governance_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Governance Toolkit (https://github.com/microsoft/agent-governance-toolkit).
Denied tool calls are short-circuited with a policy violation response.

Requires: ``pip install agentmesh-platform``
Requires: ``pip install agent-governance-toolkit-core``
"""

from __future__ import annotations
Expand All @@ -37,7 +37,7 @@


class _GovernanceUnavailableError(ImportError):
"""Raised when agentmesh-platform is not installed and fail_open=False."""
"""Raised when agent-governance-toolkit-core is not installed and fail_open=False."""


class AgentGovernancePlugin(BasePlugin):
Expand All @@ -52,7 +52,7 @@ class AgentGovernancePlugin(BasePlugin):
``*.yaml`` policy files. Resolved relative to the caller's
working directory. Must be provided explicitly.
agent_did: Decentralized identifier for the agent.
fail_open: If ``True``, tool calls proceed when ``agentmesh-platform``
fail_open: If ``True``, tool calls proceed when ``agent-governance-toolkit-core``
is not installed (logs a warning). If ``False`` (default), raises
``ImportError`` at construction time.
strict: If ``True``, raises on policy load errors instead of
Expand All @@ -61,7 +61,7 @@ class AgentGovernancePlugin(BasePlugin):
Defaults to ``False``.

Raises:
ImportError: If ``agentmesh-platform`` is not installed and
ImportError: If ``agent-governance-toolkit-core`` is not installed and
``fail_open`` is False.
RuntimeError: If ``strict`` is True and a policy file fails to load.

Expand Down Expand Up @@ -122,12 +122,12 @@ def _setup(self, *, fail_open: bool, strict: bool) -> None:
except ImportError:
if not fail_open:
raise _GovernanceUnavailableError(
"agentmesh-platform is required for governance enforcement. "
"Install with: pip install agentmesh-platform"
"agent-governance-toolkit-core is required for governance enforcement. "
"Install with: pip install agent-governance-toolkit-core"
)
logger.warning(
"agentmesh-platform not installed; governance checks disabled. "
"Install with: pip install agentmesh-platform"
"agent-governance-toolkit-core not installed; governance checks disabled. "
"Install with: pip install agent-governance-toolkit-core"
)

async def before_tool_callback(
Expand Down
35 changes: 25 additions & 10 deletions tests/plugins/test_agent_governance_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Tests for AgentGovernancePlugin.

These tests mock the agentmesh-platform dependency so they run without
These tests mock the agent-governance-toolkit-core dependency so they run without
it installed, verifying the plugin's integration with the ADK plugin API.
"""

Expand All @@ -34,7 +34,7 @@


# ---------------------------------------------------------------------------
# Mock fixtures for agentmesh-platform
# Mock fixtures for agent-governance-toolkit-core
# ---------------------------------------------------------------------------


Expand Down Expand Up @@ -169,19 +169,34 @@ def policy_dir(tmp_path: Path) -> Path:
return policies


@pytest.fixture()
def block_agentmesh():
"""Make every agentmesh import fail, even if the package is installed."""
with patch.dict(sys.modules):
_uninstall_fake_agentmesh()
# A None parent makes agentmesh and all of its submodules unimportable.
sys.modules["agentmesh"] = None
yield


class TestAgentGovernancePlugin:
"""Tests for AgentGovernancePlugin construction and behavior."""

@pytest.mark.usefixtures("block_agentmesh")
def test_raises_import_error_when_agentmesh_missing(self, tmp_path: Path):
"""Plugin raises ImportError by default when agentmesh is missing."""
# Simulate agentmesh not being importable by patching _setup
with patch.object(
AgentGovernancePlugin,
"_setup",
side_effect=ImportError("agentmesh-platform is required"),
"""Plugin raises ImportError naming the package to install."""
with pytest.raises(
ImportError, match="pip install agent-governance-toolkit-core"
):
with pytest.raises(ImportError, match="agentmesh-platform"):
AgentGovernancePlugin(policy_dir=tmp_path)
AgentGovernancePlugin(policy_dir=tmp_path)

@pytest.mark.usefixtures("block_agentmesh")
def test_fail_open_warns_with_install_hint_when_agentmesh_missing(
self, tmp_path: Path, caplog: pytest.LogCaptureFixture
):
"""With fail_open=True, the warning names the package to install."""
AgentGovernancePlugin(policy_dir=tmp_path, fail_open=True)
assert "pip install agent-governance-toolkit-core" in caplog.text

def test_fail_open_mode_allows_construction(self, tmp_path: Path):
"""With fail_open=True, plugin degrades when engine returns no policies."""
Expand Down
Loading