Plugin for Agent Development Kit (ADK) that integrates with Open Policy Agent (OPA) to enforce policies on agents and tools.
Project description
opadk
Plugin for Agent Development Kit (ADK) that integrates with Open Policy Agent (OPA) for policy enforcement on agent and tool usage.
How to use
Remote OPA server
from google.adk.runners import Runner
from opadk import OPADKPlugin, OPARemoteClient
runner = Runner(
# ...
plugins=[
OPADKPlugin(opa_client=OPARemoteClient(server_url="http://localhost:8181"))
],
)
Local client
If opa is installed locally, the OPARunClient can be used to evaluate policies without needing a separate OPA server. The client must be provided with the path to a folder with Rego policies.
from google.adk.runners import Runner
from opadk import OPADKPlugin, OPARunClient
runner = Runner(
# ...
plugins=[
OPADKPlugin(opa_client=OPARunClient(bundle_path="./rego")),
],
)
Rego Policies
The plugin will make a query that expects data.adk.tool.allow and data.adk.agent.allow rules to be defined to determine if an agent or tool can be invoked. To help the model recover from policy denials, reasoning messages can be added to the sets data.adk.tool.deny.reasons and data.adk.agent.deny.reasons.
package adk
# allow all agents by default
default agent.allow = true
# deny all tools by default
default tool.allow = false
tool.deny.reasons contains "No tools allowed"
Input Structure
The Rego policy receives the following input structure from ADK:
state: The current ADK state.agent:name: The name of the agent being invoked.
tool:name: The name of the tool being invoked.args: The arguments passed to the tool.
events: The list of events in the current session.
Example Policies
Access Control
_agents_by_user = {
"user1": {"root_agent", "it_agent"},
"user2": {"root_agent", "analytics_agent"},
}
_user_can_use_agent if {
input.agent.name in _agents_by_user[input.state.user_id]
}
agent.allow if _user_can_use_agent
agent.reasons contains sprintf(
"User does not have access to agent `%v`", [input.agent.name]
) if {
not _user_can_use_agent
}
User authorization
tool.allow if {
input.tool.name in {"update_profile"}
input.tool.args.user_id == input.state.user_id
}
Enforce parameter values
_allowed_containers := {
"python": "python:3.14-alpine@sha256:8373231e1e906ddfb457748bfc032c4c06ada8c759b7b62d9c73ec2a3c56e710",
}
_container_run_command_allowed if {
input.tool.name in {"container_run"}
input.tool.args.image == _allowed_containers[_]
}
tool.allow if {
_container_run_command_allowed
}
tool.deny.reasons contains sprintf(
"Parameter `image` must be one of: %v", [allowed_containers]
) if {
not _container_run_command_allowed
allowed_containers = [image | _allowed_containers[_] = image]
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file opadk-0.1.1.tar.gz.
File metadata
- Download URL: opadk-0.1.1.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
850254a2553b7512b2574fe18af727563a2b981410252cd12a66c0c5a347ba55
|
|
| MD5 |
4f8789f51e4d161188e3268a091cdbd9
|
|
| BLAKE2b-256 |
f9414e60e6376d6db60ae2a90d142b29ad8935d7fe834f3b6bcc8432290d174c
|
File details
Details for the file opadk-0.1.1-py3-none-any.whl.
File metadata
- Download URL: opadk-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.9.16 {"installer":{"name":"uv","version":"0.9.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e653b9a9b5944d640efa42f582b6141e2308daa1cc6c4044d6a667b32c746d3
|
|
| MD5 |
039c8654d4a8f801ede44568045327f2
|
|
| BLAKE2b-256 |
476dd5790dbf7091bd29102029565b600b5d7df95f9b349845e5f830f87e7500
|