AgentGuard Python SDK
Monitor and protect yourself with AI agent budget controls, approval workflows, and anomaly detection.
AgentGuard sits between your AI agent and its actions. Every action is validated before it runs, checking budgets, rate limits, and approval thresholds in real-time.
Install
pip install agentguard
Quick Start
from agentguard import AgentGuard
guard = AgentGuard(api_key="ag_your_api_key") # Get this from app.agent-guard.io
# Wrap any function for automatic protection
chat = guard.wrap(
my_chat_function,
action="openai_chat",
provider="openai",
model="gpt-4",
estimated_cost=0.05,
get_cost=lambda r: r.usage.total_cost,
)
# This automatically:
# ✓ Checks if agent is active
# ✓ Checks budget limits
# ✓ Checks approval thresholds
# ✓ Runs your function (only if allowed)
# ✓ Logs the result
result = chat("Hello!")
Decorator Style
@guard.protect(action="openai_chat", estimated_cost=0.05)
def chat(prompt):
return openai.chat(prompt=prompt)
result = chat("Hello!")
Core Methods
guard.check(action, estimated_cost) — Pre-action validation
result = guard.check("openai_chat", estimated_cost=0.05)
if result.allowed:
response = openai.chat(prompt="Hello")
else:
print(f"Blocked: {result.message}")
guard.log(action, ...) — Log an action
guard.log(
"api_call",
provider="openai",
model="gpt-4",
cost=0.05,
status="SUCCESS",
input_tokens=10,
output_tokens=25,
)
guard.track(action) — Track duration
done = guard.track("openai_chat", provider="openai")
result = openai.chat(prompt="Hello")
done(cost=0.05, response=result)
# Duration is calculated automatically
Budget Management
# Get current budget status
budget = guard.get_budget()
print(f"Spent: ${budget.budget_spent} / ${budget.budget_limit}")
# Check if a specific cost is within budget
check = guard.check_budget(0.50)
if not check.allowed:
print("Would exceed budget")
# Raise if over budget
guard.ensure_budget(0.50) # raises BudgetExceededError if over
Approval Workflows
# Request approval for a high-cost action
approval = guard.request_approval(
"send_bulk_email",
description="Send marketing email to 10,000 users",
estimated_cost=45.00,
)
# Wait for human decision (polls every 5 seconds)
try:
decided = guard.wait_for_approval(approval.id, timeout=3600)
print("Approved! Proceeding...")
except AgentGuardError:
print("Rejected or expired")
Error Handling
from agentguard import (
AgentGuardError, # Base error
AgentPausedError, # Agent is paused
AgentBlockedError, # Agent is blocked (kill switch)
BudgetExceededError, # Budget limit hit
ApprovalRequiredError, # Needs human approval
)
try:
result = chat("Hello!")
except AgentPausedError:
print("Agent paused — stopping gracefully")
except BudgetExceededError:
print("Budget exceeded — waiting for reset")
except ApprovalRequiredError as e:
print(f"Approval needed: {e.approval_id}")
Configuration
guard = AgentGuard(
api_key="ag_your_api_key", # Required
base_url="https://api.agent-guard.io", # Optional
timeout=10, # Optional: seconds (default: 10)
debug=False, # Optional: debug logging (default: False)
)
Dashboard
Manage your agents, view logs, approve actions, and monitor budgets at app.agent-guard.io
Links
License
MIT
Metadata
Release files for agentguard-py 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agentguard_py-0.1.1.tar.gz | 10.6 kB | Without provenance | Details for agentguard_py-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agentguard_py-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for agentguard_py-0.1.1-py3-none-any.whl |
Total release size: 20.6 kB
Release files / agentguard_py-0.1.1.tar.gz
| Download URL | agentguard_py-0.1.1.tar.gz |
|---|---|
| Size | 10.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3fd4cde20205277d3ef726219ce6480a19a73ae0ec8fc241d87b5e4050287d95
|
|
BLAKE2b-256 checksum How to use checksums |
b0a3343e91f0a0ba395bb4db39776f9353fb5e98935107d7a50073f1f43411b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / agentguard_py-0.1.1-py3-none-any.whl
| Download URL | agentguard_py-0.1.1-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9a9db3aa642b8046e146d6f44e57ddb26590641d8e1cff2d80649c492df83996
|
|
BLAKE2b-256 checksum How to use checksums |
83ddae366b5caeb904fba3ae8abcce5d615f1690ae34d65600abde3cbdd1a0c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for agentguard-py 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.