Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 1.0.1 instead.

AgentGuard Python SDK

A production-quality Python SDK for integrating AI agents with the AgentGuard security system.

What is AgentGuard?

AgentGuard is an end-to-end security pipeline for autonomous AI agents. It protects your tools and systems by strictly mediating agent actions through an approval pipeline involving Cedar authorization policies, dynamic ML threat detection (like prompt injection), and a human-in-the-loop approval workflow.

Why it exists?

AI agents are increasingly given access to sensitive systems (email, file systems, internal APIs). Without a robust gateway, a compromised agent or prompt-injected LLM can exfiltrate data, perform destructive operations, or perform unauthorized actions. AgentGuard provides a transparent security layer to prevent this.

Installation

You can install the SDK locally from the project root:

pip install -e sdk/python/

Basic Usage

The SDK defaults to a fail-closed behavior, meaning if the AgentGuard server is unreachable, actions are securely BLOCKED.

Initialization

import os
from agentguard import AgentGuard, AgentGuardBlocked, ApprovalRequired

# Initialize with explicit parameters or environment variables 
# (AGENTGUARD_AGENT_ID, AGENTGUARD_URL, AGENTGUARD_USER_ID)
guard = AgentGuard(
    agent_id="research-agent",
    server="http://localhost:8000"
)

The .require() method abstracts the decision handling into standard exceptions.

try:
    # If ALLOW, execution continues normally.
    guard.require("file_read", "read", arguments={"path": "report.pdf"})
    print("Action allowed! Executing tool...")
    
except ApprovalRequired as e:
    # If APPROVE, an approval is created and human operator must review.
    print(f"Action requires human approval: {e.reason}")
    
except AgentGuardBlocked as e:
    # If BLOCK, execution is halted immediately.
    print(f"Action was strictly blocked: {e.reason}")

ALLOW / APPROVE / BLOCK Semantics

AgentGuard evaluates all requests and returns one of three decisions:

  1. ALLOW: The action is safe according to permissions, policies, and threat detection.
  2. APPROVE: The action is sensitive (e.g. external communication) and requires a human operator to review it via the AgentGuard TUI or API.
  3. BLOCK: The action is explicitly prohibited or highly dangerous (e.g. prompt injection, unauthorized agent).

Fail-Closed Behavior

If the AgentGuard server is down, unreachable, or returns a 500 error, the SDK gracefully defaults to a fail-closed posture. The decision returned will be BLOCK, and .require() will raise an AgentGuardConnectionError. This ensures AI agents do not bypass security during outages.

MCP Integration

If you are exposing your tools using the Model Context Protocol (MCP), you can integrate this SDK into your MCP Gateway to strictly enforce AgentGuard decisions over the JSONRPC streams. See the agentguard/backend/app/mcp/mcp_server.py file for a full implementation.

Architecture

AI Agent / MCP Client
        |
        | Tool Call (e.g., email_send)
        v
    AgentGuard SDK  --> HTTP POST /v1/authorize --> [ AgentGuard Server ]
        |                                           [ - Cedar Policy    ]
        |                                           [ - Risk Engine     ]
        v                                           [ - ML Threat Detect]
   ALLOW / BLOCK / APPROVE                          [ - Persistent Audit]
        |
        v
 Protected Tool

Metadata

Release files for agentguard-shield 1.0.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-shield 1.0.0
File Size Uploaded
agentguard_shield-1.0.0.tar.gz 10.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for agentguard-shield 1.0.0
File Interpreter ABI Platform
agentguard_shield-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.7 kB

Release files / agentguard_shield-1.0.0.tar.gz

Download URL agentguard_shield-1.0.0.tar.gz
Size 10.3 kB
Tags Source
SHA-256 checksum
How to use checksums
73c0db0a8776eba03016be2eb5436bf892b62809fb77d9d62ee6b7041307f775
BLAKE2b-256 checksum
How to use checksums
fe183d3c4fd5194c0d6f056f76b2a769958e940eafa649f50239083d7cd26d7a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / agentguard_shield-1.0.0-py3-none-any.whl

Download URL agentguard_shield-1.0.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6445a090b6c2cfe3faf8e36a976bfd75506e42220ec164810d7552d4c546e52
BLAKE2b-256 checksum
How to use checksums
c293a0d4958986988ed1f233e8e6378dd9790f4341019ca4060681b855a33655
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release history Release notifications | RSS feed

1.0.1

2 release files

This release

1.0.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