Catalog PyPI
Back to packageRELEASE DETAILS

1.0.1

PyPI

agentshield-spend

A firewall for AI agent spending. 9 composable rules evaluated per-transaction in <1ms. Pure Python stdlib — zero dependencies.

agentaianthropicapi-costsbudgetcostcost-managementfirewalllangchainllmopenairate-limitspendspend-controltoken
Published11 Aug 2026
Direct dependencies0
Transitive dependenciesNot calculated

README

Version 1.0.1 documentation

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-spend

(The import name is agentshield — the PyPI name agentshield belongs to an unrelated project.)

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)

RuleDescriptionExample Params
transaction_limitBlock single calls over $X{"max_amount": 500}
daily_totalCap cumulative daily spend{"max_daily": 2000}
velocityDetect burst patterns{"window_minutes": 60, "max_count": 10}
merchant_allowlistOnly approved API providers{"allowed": ["openai-api", "anthropic-api"]}
category_blockBlock spend categories{"blocked": ["crypto_exchange"]}
session_budgetPer-session spend cap with decay{"max_session": 100, "decay_factor": 0.3}
cascade_costExpected 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

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 0

Native requirements
0 direct targetsNot calculated transitive count
No declared dependencies in this collected response

Declarations describe requirements; they are not a resolved dependency graph.

Distribution files

2 collected
agentshield_spend-1.0.1-py3-none-any.whl

bdist_wheel · 12.56 KB · Python py3

Source file
agentshield_spend-1.0.1.tar.gz

sdist · 12.73 KB · Python source

Source file

Repository

PENDING
kindrat86/agentshield

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 23:22 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:268d3bdc1694dbf153061eee89f134c28bbce02143fd1a2f4bbe47dde582be32

Other collected versions

View all collected versions →