Skip to main content

AgentGuard Python SDK

Policy engine for securing AI agent tool calls. | AI Agent 工具调用安全策略引擎。


Installation | 安装

pip install agent-guard

Requires Python >= 3.10. | 需要 Python >= 3.10。

From source | 源码安装:

cd python
pip install -e ".[dev]"

Quick Start | 快速开始

import asyncio
from agent_guard import PolicyEngine, guard

engine = PolicyEngine("policy.yaml")

@guard(engine, session_id="demo")
async def shell_execute(command: str) -> str:
    return f"执行结果: {command}"

async def main():
    result = await shell_execute("echo hello")
    print(result)

asyncio.run(main())

API

PolicyEngine(config_path: str = "policy.example.yaml")

Load policies from a YAML file. | 从 YAML 文件加载策略。

  • execute_pre(tool_name, args, session_id) — Run pre-execution policies | 执行前置策略检查
  • execute_post(tool_name, result, session_id) — Run post-execution policies | 执行后置策略处理

@guard(engine, session_id="default")

Decorator that wraps an async function with policy enforcement. | 装饰器,为异步函数添加策略防护。

SuspensionManager

  • create_request() — Create a suspension request | 创建挂起请求
  • wait_for_approval() — Wait for human approval (asyncio.Event) | 等待人工审批
  • approve(request_id) / reject(request_id, reason) — External wake-up | 外部唤醒接口
  • list_pending() — List all pending requests | 列出待审批请求

Development | 开发

cd python
pip install -e ".[dev]"
pytest --cov=agent_guard --cov-report=term-missing

License | 开源许可证

MIT License — Copyright (c) 2026 guorui999

Metadata

Release files for agenttoolguard 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 agenttoolguard 0.1.1
File Size Uploaded
agenttoolguard-0.1.1.tar.gz 8.2 kB Details

Built distribution (wheel)

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

Total release size: 15.7 kB

Release files / agenttoolguard-0.1.1.tar.gz

Download URL agenttoolguard-0.1.1.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b5999ad04708a5903cd94d97117b81fa581f479208b19f990a32033b4679f122
BLAKE2b-256 checksum
How to use checksums
fbd455ca8a741a205d85e6d71442c343e43422280c2a23fff6ff00d9b9258942
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

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

Download URL agenttoolguard-0.1.1-py3-none-any.whl
Size 7.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
502a25778d7469351f0bd7d4eb4207976a1a68f41d6e573a50fdd42321490abd
BLAKE2b-256 checksum
How to use checksums
4828caa159d73d0cc1eb61448c0ac83d27479b63246c5995f93fe6850beebf36
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

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