Skip to main content

agentguard-governance-sdk

Official Python Developer SDK for the AgentGuard runtime governance and policy enforcement layer.

AgentGuard intercepts proposed AI agent tool calls before dispatch, evaluates them against organizational RBAC, risk policies, token/rate limits, and cost budgets, and logs decisions to a cryptographic tamper-evident audit vault.


Installation

pip install agentguard-governance-sdk

Requirements: Python 3.9+ with httpx and pydantic.


Core Usage

Standard Exception-Driven Pattern

By default, client.guard(...) returns a GuardResult on ALLOW, and raises structured exceptions when an action is blocked or queued for approval:

from agentguard import (
    AgentGuard,
    AgentGuardDenied,
    AgentGuardPending,
    AgentGuardAuthenticationError,
    AgentGuardTimeout,
    AgentGuardServerError,
)

# Initialize client
client = AgentGuard(
    api_key="ag_agent_your_key_here",
    base_url="http://localhost:8000/api/v1",  # Core Engine Gateway URL
)

try:
    result = client.guard(
        tool="read_customer",
        parameters={"customer_id": "CUST-1001"},
        estimated_tokens=50,
        estimated_cost=0.001,
    )
    if result.allowed:
        print(f"Action allowed! Request ID: {result.request_id}")
        # Safely execute the real tool call here

except AgentGuardDenied as e:
    # Action was rejected by policy (e.g. CRITICAL risk, unpermitted tool, rate/budget exceeded)
    print(f"Action DENIED: {e.reason} (request_id={e.request_id})")

except AgentGuardPending as e:
    # Action requires human-in-the-loop (HITL) approval
    print(f"Action paused for human approval: {e.reason} (request_id={e.request_id})")

except AgentGuardAuthenticationError as e:
    print(f"Authentication failed (HTTP {e.status_code}): {e.detail}")

except AgentGuardTimeout as e:
    print(f"Connection to AgentGuard timed out or was refused: {e}")

except AgentGuardServerError as e:
    print(f"AgentGuard backend error (HTTP {e.status_code}): {e.detail}")

finally:
    client.close()

Context Manager Support

AgentGuard instances can be managed automatically via a with block:

from agentguard import AgentGuard

with AgentGuard(api_key="ag_agent_...") as client:
    result = client.guard(tool="send_email", parameters={"to": "user@example.com"})
    print("Allowed:", result.allowed)

Non-Raising / Boolean Return Mode

Pass raise_for_status=False to inspect decisions via the returned GuardResult without catching exceptions:

with AgentGuard(api_key="ag_agent_...") as client:
    result = client.guard(
        tool="process_refund",
        parameters={"amount": 5000},
        raise_for_status=False,
    )

    if result.allowed:
        print("Proceeding with refund...")
    elif result.decision == "PENDING":
        print(f"Queued for human review. Request ID: {result.request_id}")
    elif result.decision == "DENY":
        print(f"Refund denied: {result.reason}")

API Reference

AgentGuard Constructor

AgentGuard(
    api_key: str,
    base_url: str = "http://localhost:8000/api/v1",
    agent_id: Optional[Union[uuid.UUID, str]] = None,
    timeout: float = 5.0,
    max_retries: int = 1,
    retry_backoff: float = 0.2,
    http_client: Optional[httpx.Client] = None,
)

client.guard(...) Parameters

Parameter Type Default Description
tool str required Name of the tool to be executed (e.g. "read_customer").
parameters dict {} Key-value dictionary of arguments for the tool.
action str "execute" Action verb associated with the tool call.
agent_id UUID | str None Optional override for the requesting agent UUID.
estimated_tokens int 0 Estimated token usage for sliding-window token rate limiting.
estimated_cost float 0.0 Estimated monetary spend for budget enforcement.
metadata dict None Custom context or telemetry dictionary attached to audit log.
timeout float None Per-request timeout override in seconds.
max_retries int None Per-request network retry attempts (safe network failures only).
raise_for_status bool True If True, raises AgentGuardDenied or AgentGuardPending. If False, returns GuardResult with .allowed=False.

GuardResult Object Attributes

  • allowed (bool): True if permitted, False otherwise.
  • decision (str): "ALLOW", "DENY", or "PENDING".
  • request_id (str): Server-generated UUID uniquely tracking this evaluation in the audit vault.
  • reason (str): Human-readable explanation of policy decision.
  • raw_response (dict): Raw JSON response dictionary from the gateway.

Exception Hierarchy

AgentGuardError (Base Exception)
├── AgentGuardDenied (Action blocked by policy)
│   ├── reason: str
│   └── request_id: Optional[str]
├── AgentGuardPending (Action paused for human approval)
│   ├── reason: str
│   └── request_id: Optional[str]
├── AgentGuardAuthenticationError (HTTP 401/403)
│   ├── status_code: int
│   └── detail: Optional[str]
├── AgentGuardTimeout (Unreachable / network dropped)
│   └── message: str
└── AgentGuardServerError (HTTP 5xx / unexpected response)
    ├── status_code: int
    ├── detail: Optional[str]
    └── raw_response: Optional[str]

Release files for agentguard-governance-sdk 0.1.0

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

Source distribution (sdist)

Source distribution for agentguard-governance-sdk 0.1.0
File Size Uploaded
agentguard_governance_sdk-0.1.0.tar.gz 13.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentguard-governance-sdk 0.1.0
File Interpreter ABI Platform
agentguard_governance_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.2 kB

Release files / agentguard_governance_sdk-0.1.0.tar.gz

Download URL agentguard_governance_sdk-0.1.0.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3b9daaa3caec2aaba365a98fa30aa0222c9e694ec500185c50feea7c7bf86ac1
BLAKE2b-256 checksum
How to use checksums
3bae7e4cc814aeaf17dde10d4ec0e8c67297ba738f70d57b7bfae15bdc101f82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / agentguard_governance_sdk-0.1.0-py3-none-any.whl

Download URL agentguard_governance_sdk-0.1.0-py3-none-any.whl
Size 10.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68919e0228f0026803405965b4d1e4f8dab06c319caae72f5a5a9f85f37169e5
BLAKE2b-256 checksum
How to use checksums
9e8a004ff582fb288397ee3fbf66052edae0114760cf984f0552c7a488a98e56
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.1.0 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