feat(governance): add SidClaw governance service integration#114
feat(governance): add SidClaw governance service integration#114VladUZH wants to merge 1 commit intogoogle:mainfrom
Conversation
Add policy evaluation, human-in-the-loop approval, and tamper-proof audit trails for ADK agent tool calls via the SidClaw platform. - Integrates via ADK's before_tool_callback and after_tool_callback - Evaluates tool calls against SidClaw policies (allow/deny/approval) - Records execution outcomes in hash-chain audit trail - Configurable per-tool data classifications and approval behavior - Fail-closed by default when SidClaw is unreachable - 20 unit tests covering all decision paths and error cases Closes google#113 Related-To: google/adk-python#5081
|
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. |
|
@google-cla I've signed the CLA — can you re-check? |
|
CLA check is green now. This adds a SidClaw governance middleware sample — wraps ADK tool calls with policy evaluation and human approval. Happy to adjust anything to match the repo's conventions. |
|
@gemini-cli /review |
|
🤖 Hi @DeanChensj, I've received your request, and I'm working on it now! You can track my progress in the logs for more details. |
There was a problem hiding this comment.
Thanks for the contribution! The integration looks solid and well-tested. I've left a few comments regarding type safety and edge-case handling. Specifically:
- Consider more specific type annotations for
tool_contextif possible. - Ensure robust handling of
tool_contextand itsstateto avoid potentialAttributeErrororKeyError. _safe_serializecould be made more robust for deeply nested or complex non-dict structures.
Otherwise, the implementation follows the expected patterns and the tests are comprehensive.
| ) | ||
| """ | ||
|
|
||
| def __init__( |
There was a problem hiding this comment.
This is a good practice to ensure AsyncSidClaw is available when the service is initialized.
| "The sidclaw package is required for SidClaw " | ||
| "governance. Install it with: pip install sidclaw" | ||
| ) from _SIDCLAW_IMPORT_ERROR | ||
|
|
There was a problem hiding this comment.
Is it possible for tool_context to be None here? If so, we should add a check to avoid an AttributeError. Also, the type annotation for tool_context is Any. If there is a more specific type available in ADK, it would be better to use it.
| "target_integration": "google_adk", | ||
| "resource_scope": self._config.resource_scope, | ||
| "data_classification": classification, | ||
| "context": { |
There was a problem hiding this comment.
Should we also log the trace ID when fail_open is triggered? It might be useful for debugging why the evaluation failed.
| return None | ||
| return { | ||
| "error": ( | ||
| "Governance evaluation failed — tool blocked. " |
There was a problem hiding this comment.
Is it possible for tool_context.state to be missing? We should ensure that this doesn't raise a KeyError or AttributeError if tool_context is not as expected.
|
|
||
|
|
||
| def _safe_serialize(obj: Any) -> Any: | ||
| """Convert args to a JSON-safe dict for the SidClaw context.""" |
There was a problem hiding this comment.
The _safe_serialize function handles dict by stringifying non-primitive values. However, if obj is not a dict, it just returns {"raw": str(obj)}. This might be too simplistic for some complex arguments. Have you considered using something like pydantic.json.pydantic_encoder or a similar robust serializer if available? For example, if an argument is a list of complex objects.
Summary
Add a governance service for Google ADK agents using SidClaw — policy evaluation, human-in-the-loop approval, and tamper-proof audit trails for tool calls.
Closes #113
Background
This submission was invited by @rohityan in google/adk-python#5081:
CLA: Already signed for google/adk-python#5081.
What It Does
The
SidClawGovernanceServiceintegrates with ADK'sbefore_tool_callbackandafter_tool_callbackhooks:Before tool execution:
After tool execution:
Files Changed
src/google/adk_community/governance/__init__.pysrc/google/adk_community/governance/sidclaw_governance.pytests/unittests/governance/__init__.pytests/unittests/governance/test_sidclaw_governance.pypyproject.tomlsidclaw>=0.1.2dependencyConfiguration
default_classification"internal"tool_classifications{}{"delete_db": "restricted"})resource_scope"google_adk"wait_for_approvalTruefail_openFalseTesting Plan
Unit Tests
All 20 unit tests pass:
Coverage includes:
Manual E2E Testing
Verified with SidClaw platform (https://api.sidclaw.com):
Links