Skip to main content

Thin Python SDK for the Agentic Control Plane governance hook protocol. Wrap any tool call; ACP decides allow/deny/redact.

Project description

acp-governance

Thin Python SDK for the Agentic Control Plane governance hook protocol.

Wraps the two endpoints ACP exposes:

  • POST /govern/tool-use — pre-tool check (allow / deny / ask)
  • POST /govern/tool-output — post-tool audit + PII scan

Same protocol Claude Code uses. Works with any Python agent runtime.

Install

pip install acp-governance

Usage

from fastapi import FastAPI, Header
from acp_governance import governed, set_context

app = FastAPI()

@governed("web_search")
def web_search(query: str) -> str:
    """Search the web."""
    return my_search(query)  # your code, your credentials

@app.post("/run")
def run(topic: str, authorization: str = Header(...)):
    token = authorization.removeprefix("Bearer ").strip()
    set_context(user_token=token)
    return {"result": web_search(topic)}

What happens per call

  1. pre_tool_use POSTs to /govern/tool-use with { tool_name, tool_input, session_id } + Authorization: Bearer <user-jwt>.
  2. Gateway evaluates policy, rate limits, scope, PII → returns { decision, reason }.
  3. On deny, the wrapped function short-circuits with "tool_error: <reason>" (the model sees it and adapts).
  4. On allow, the function runs. Result is sent to /govern/tool-output for audit.
  5. If gateway returns action: "redact", the redacted output is returned to the caller.

Fail-open

Network errors, timeouts (5s), non-2xx responses → tool proceeds with reason "fail-open". Governance is never a single point of failure for the agent.

Framework adapters

This package is the core. For framework-native usage:

API

# decorator
governed(name_or_fn=None)                    # @governed or @governed("tool_name")

# context binding
set_context(user_token, *, session_id=None, agent_tier=None, agent_name=None)
get_context()
clear_context()

# manual (if you need to hook somewhere other than a function boundary)
pre_tool_use(tool_name, tool_input) -> (allowed, reason)
post_tool_output(tool_name, tool_input, tool_output) -> response_dict | None

# config
configure(base_url=..., timeout_s=..., client_header=...)
get_config()

Supports both sync and async tool functions — @governed detects via inspect.iscoroutinefunction and dispatches accordingly.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

acp_governance-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

acp_governance-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file acp_governance-0.1.0.tar.gz.

File metadata

  • Download URL: acp_governance-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for acp_governance-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8cdc3e0eb68831e8c91022d8e66d511ff534f101a4d6b867d7c02eaa58aa6507
MD5 f0e2fa9150c550fca0769d292b6906ca
BLAKE2b-256 6d41ebaf0ccbcc1905972e2fb6d525ab9729c148fb548396b46da0646e201308

See more details on using hashes here.

File details

Details for the file acp_governance-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: acp_governance-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for acp_governance-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 957169507461145126c5ba3f565cb72877894db2e35f28d155ebc99586c6cafb
MD5 cf68573e01db83f8d8f57ed34a3edf88
BLAKE2b-256 2ff16bb90d9c63612f53ecaba9ea7f24a61c065c800a600738f41394fcd58dee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page