AgentShield — Firewall for AI Agent Spending
Stop runaway AI agents before they burn your budget. 9 composable rules evaluated per-transaction in <1ms. Pure Python stdlib — zero dependencies.
Install
pip install agentshield
Quick Start
from agentshield import SpendControlEngine
engine = SpendControlEngine()
# A transaction your agent wants to make
transaction = {
"amount": 500.00,
"merchant": "openai-api",
"category": "llm_inference",
"agent_id": "my-agent",
"timestamp": "2026-08-10T10:00:00Z",
}
# Your spend-control rules
rules = [
{"id": "r1", "type": "transaction_limit", "priority": 1,
"params": {"max_amount": 250}, "action": "BLOCK"},
{"id": "r2", "type": "daily_total", "priority": 2,
"params": {"max_daily": 2000}, "action": "BLOCK"},
{"id": "r3", "type": "velocity", "priority": 3,
"params": {"window_minutes": 60, "max_count": 10}, "action": "FLAGGED"},
]
# Prior transactions today (for daily_total and velocity checks)
prior_transactions = []
# Evaluate — returns in <1ms
result = engine.evaluate(transaction, rules, prior_transactions)
print(result["decision"]) # BLOCKED
print(result["reason"]) # Transaction amount $500.00 exceeds limit of $250.00
Rule Types (9)
| Rule | Description | Example Params |
|---|---|---|
transaction_limit |
Block single calls over $X | {"max_amount": 500} |
daily_total |
Cap cumulative daily spend | {"max_daily": 2000} |
velocity |
Detect burst patterns | {"window_minutes": 60, "max_count": 10} |
merchant_allowlist |
Only approved API providers | {"allowed": ["openai-api", "anthropic-api"]} |
category_block |
Block spend categories | {"blocked": ["crypto_exchange"]} |
session_budget |
Per-session spend cap with decay | {"max_session": 100, "decay_factor": 0.3} |
cascade_cost |
Expected value with retry cost | {"max_cascade_cost": 100, "fail_probability": 0.3, "reversal_cost": 200} |
Eval Gym (56 scenarios)
from agentshield import run_eval
results = run_eval()
print(f"{results['passed']}/{results['total']} passed") # 56/56
All 56 test scenarios are MIT licensed. Use them as test fixtures for your own spend-control implementation.
Key Design Decisions
- Pure Python 3.11 stdlib — no pip install required (except for the package wrapper itself)
- Decimal for money — never float, always
decimal.Decimal - Stateless — no file I/O, no network, no global state
- Deterministic — same inputs always produce the same output
- <1ms per evaluation
Links
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
agentshield_spend-1.0.0.tar.gz
(12.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agentshield_spend-1.0.0.tar.gz.
File metadata
- Download URL: agentshield_spend-1.0.0.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d13688d4e91115aada6d21c50dd9ba5e6620225c15fa68f38603995964965655
|
|
| MD5 |
0aab6ee2927ffc0ac64daaa8e90a1180
|
|
| BLAKE2b-256 |
ac404ce7aa229a84721eb7f1091d101d900af42267fac76ab24a0bf6a78c29ea
|
File details
Details for the file agentshield_spend-1.0.0-py3-none-any.whl.
File metadata
- Download URL: agentshield_spend-1.0.0-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e32654c7389a2e4c4dfa5f6b45130325e0ceb9562f088ba7bdcccf86ecffe90
|
|
| MD5 |
35edc6c0e7e4377acab830683743819d
|
|
| BLAKE2b-256 |
b9fed914b6ad14779c2952e51b4cc55446feb29d5123eca3776baa43839d1cdd
|