Skip to content

fix: point install hint at agent-governance-toolkit-core - #187

Open
thecvcodes wants to merge 1 commit into
google:mainfrom
thecvcodes:fix/186-install-hint
Open

thecvcodes wants to merge 1 commit into
google:mainfrom
thecvcodes:fix/186-install-hint

Conversation

@thecvcodes

Copy link
Copy Markdown

Fixes #186

Summary

AgentGovernancePlugin tells users to pip install agentmesh-platform when agentmesh can't be imported. That package is deprecated; agentmesh now ships in agent-governance-toolkit-core.

  • Replace agentmesh-platform with agent-governance-toolkit-core in the plugin's error and warning messages, its docstrings, and contributing/samples/agent_governance/README.md. The replacements are in place, with no other reformatting.
  • Replace test_raises_import_error_when_agentmesh_missing. It patched _setup to raise a mocked ImportError, so it only asserted on the mock's own message and never exercised the plugin's. The new test blocks the real agentmesh import through a block_agentmesh fixture and asserts on the actual message.
  • Add test_fail_open_warns_with_install_hint_when_agentmesh_missing to cover the fail_open=True warning.

The fixture removes any loaded agentmesh* modules and sets sys.modules["agentmesh"] = None. Both tests therefore pass whether or not AGT is installed, even if it was imported earlier in the session.

Testing plan

  • Unit tests: run the plugin tests with AGT absent, with AGT installed, and with AGT imported before the tests start. Confirm that the two new tests fail against the previous plugin code.
  • E2E: construct an InMemoryRunner with the plugin in an environment without AGT, for both fail_open modes, and check the user-facing text.

pytest results

$ pytest tests/plugins/test_agent_governance_plugin.py
15 passed                                   # AGT not installed
15 passed                                   # agent-governance-toolkit-core 5.0.0 installed
15 passed                                   # agentmesh imported before pytest runs

$ pytest tests/plugins/test_agent_governance_plugin.py -k missing   # against previous plugin code
FAILED ...::test_raises_import_error_when_agentmesh_missing
FAILED ...::test_fail_open_warns_with_install_hint_when_agentmesh_missing

$ pytest tests/plugins
26 passed

$ pytest tests/unittests
79 passed

tests/plugins isn't part of the CI run (pytest tests/unittests), so the results above are from a local run on Python 3.11. tests/unittests needed greenlet installed locally: test_hitl_approval_api.py fails to collect on main without it, because the hitl extra doesn't pull it in. That's unrelated to this change.

E2E: Runner without AGT installed

import logging
from google.adk.agents import LlmAgent
from google.adk.runners import InMemoryRunner
from google.adk_community.plugins import AgentGovernancePlugin

logging.basicConfig(level=logging.WARNING, format="%(levelname)s %(name)s: %(message)s")
agent = LlmAgent(name="demo", model="gemini-2.5-flash", instruction="demo")

print("--- fail_open=False (default) ---")
try:
    InMemoryRunner(agent=agent, plugins=[AgentGovernancePlugin(policy_dir="policies")])
except ImportError as exc:
    print(f"{type(exc).__name__}: {exc}")

print("--- fail_open=True ---")
runner = InMemoryRunner(agent=agent, plugins=[AgentGovernancePlugin(policy_dir="policies", fail_open=True)])
print("Runner created with plugins:", [p.name for p in runner.plugin_manager.plugins])
$ python -u e2e_runner_missing_agt.py
--- fail_open=False (default) ---
_GovernanceUnavailableError: agent-governance-toolkit-core is required for governance enforcement. Install with: pip install agent-governance-toolkit-core
--- fail_open=True ---
WARNING google.adk_community.plugins.agent_governance_plugin: agent-governance-toolkit-core not installed; governance checks disabled. Install with: pip install agent-governance-toolkit-core
Runner created with plugins: ['agent_governance']

agentmesh-platform is deprecated; agentmesh now ships in
agent-governance-toolkit-core. Update the error/warning messages,
docstrings and sample README, and replace the stubbed _setup test with
ones that block the real agentmesh import.

Fixes google#186
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.

AgentGovernancePlugin: install hint points at deprecated agentmesh-platform

1 participant