Skip to main content

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]
}

Metadata

Release files for opadk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for opadk 0.1.1
File Size Uploaded
opadk-0.1.1.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for opadk 0.1.1
File Interpreter ABI Platform
opadk-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 kB

Release files / opadk-0.1.1.tar.gz

Download URL opadk-0.1.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
850254a2553b7512b2574fe18af727563a2b981410252cd12a66c0c5a347ba55
BLAKE2b-256 checksum
How to use checksums
f9414e60e6376d6db60ae2a90d142b29ad8935d7fe834f3b6bcc8432290d174c
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / opadk-0.1.1-py3-none-any.whl

Download URL opadk-0.1.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e653b9a9b5944d640efa42f582b6141e2308daa1cc6c4044d6a667b32c746d3
BLAKE2b-256 checksum
How to use checksums
476dd5790dbf7091bd29102029565b600b5d7df95f9b349845e5f830f87e7500
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page