Drop-in middleware that gives AI agents hard spending limits, token budgets, circuit breakers, and real-time kill switches.
Project description
💰 agent-wallet
Add two lines of code and your agent can never spend more than you allow. Ever. Even while you sleep.
agent-wallet is a drop-in middleware library that gives AI agents hard spending limits, token budgets, circuit breakers, and real-time kill switches via messaging apps (Telegram, WhatsApp, Discord).
The Problem
Agents running overnight can spend hundreds of dollars before anyone notices. Cost surprises are the #1 complaint from OpenClaw users — one documented case shows a single "hi" message costing $11 with a premium model. No existing OSS library enforces budget constraints at the provider call level.
Quick Start
pip install sr-agent-wallet
from agent_wallet import AgentWallet
from anthropic import Anthropic
wallet = AgentWallet(daily_limit_usd=5.00, kill_switch='telegram')
client = wallet.wrap(Anthropic()) # drop-in replacement
# Use exactly like the original client — but with budget enforcement
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello!"}],
)
Features
- 🔒 Hard spend caps per day / week / session in USD
- 👛 Per-agent wallets with isolated budgets
- 📉 Auto-downgrade — switches to a cheaper model as budget tightens
- 🛑 Kill switch — text "STOP" to Telegram/Discord → agent pauses instantly
- 🔔 Alerts at configurable thresholds (default: 80%)
- 📊 Local SQLite ledger — no cloud, no dashboard required
- 🔌 Multi-provider — Anthropic, OpenAI, Google Gemini, Ollama
Auto-Downgrade
Automatically switch to cheaper models as your budget tightens:
from agent_wallet import AgentWallet, AutoDowngradeStep
wallet = AgentWallet(
name="research-bot",
daily_limit_usd=10.00,
auto_downgrade=[
AutoDowngradeStep(
at_budget_pct=0.6,
from_model="claude-opus-4-6",
to_model="claude-sonnet-4-6",
provider="anthropic",
),
AutoDowngradeStep(
at_budget_pct=0.85,
from_model="claude-sonnet-4-6",
to_model="claude-haiku-4-5-20251001",
provider="anthropic",
),
],
)
Kill Switch
Send a message from your phone to pause any agent instantly:
STOP research-bot → pauses the wallet
RESUME research-bot → resumes it
STATUS → shows all wallet statuses
Supported platforms
- Telegram — set
TELEGRAM_BOT_TOKENandTELEGRAM_CHAT_ID - Discord — set
DISCORD_WEBHOOK_URL - Generic webhook — any HTTP endpoint
CLI
agent-wallet status # show all wallets
agent-wallet status --wallet my-agent # show specific wallet
agent-wallet pause my-agent # pause a wallet
agent-wallet resume my-agent # resume a wallet
agent-wallet history --days 7 # show spend history
agent-wallet wallets list # list all wallets
agent-wallet wallets create bot --daily 10.00
Environment Variables
| Variable | Default | Description |
|---|---|---|
AGENT_WALLET_DB |
~/.agent-wallet/ledger.db |
SQLite database path |
AGENT_WALLET_PRICING |
(bundled) |
Custom pricing manifest |
AGENT_WALLET_DISABLED |
unset | Set to 1 to disable all interception |
TELEGRAM_BOT_TOKEN |
— | Telegram bot token |
TELEGRAM_CHAT_ID |
— | Telegram chat ID |
DISCORD_WEBHOOK_URL |
— | Discord webhook URL |
Development
pip install -e ".[dev]"
pytest tests/ -v
mypy agent_wallet/ --strict
ruff check agent_wallet/
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 sr_agent_wallet-0.1.0.tar.gz.
File metadata
- Download URL: sr_agent_wallet-0.1.0.tar.gz
- Upload date:
- Size: 42.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57b6b075db6cada631a40711fe6a3037a2574ef24026a734b74a3e2136642d4c
|
|
| MD5 |
6ed4cfe8691666108d614e1819510793
|
|
| BLAKE2b-256 |
a523e42c2e972a02ac8a1fe60ea078ae9edf5395f4d38985d7e7440f93e9282c
|
Provenance
The following attestation bundles were made for sr_agent_wallet-0.1.0.tar.gz:
Publisher:
publish.yml on routsom/agent-wallet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sr_agent_wallet-0.1.0.tar.gz -
Subject digest:
57b6b075db6cada631a40711fe6a3037a2574ef24026a734b74a3e2136642d4c - Sigstore transparency entry: 1586968799
- Sigstore integration time:
-
Permalink:
routsom/agent-wallet@9ef9a38f23cf2d4499504cc52c44c2da793445f0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/routsom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9ef9a38f23cf2d4499504cc52c44c2da793445f0 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sr_agent_wallet-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sr_agent_wallet-0.1.0-py3-none-any.whl
- Upload date:
- Size: 36.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7d63cda3e0b37f12557031db0bff039a58e483fba24496bbdf84a73cd58c88d
|
|
| MD5 |
f66b149f0dc28b318f275f4309ac1168
|
|
| BLAKE2b-256 |
44bca902d7bb26d499638bc276b74bdb3165f979d12c207340be47cd638e0aee
|
Provenance
The following attestation bundles were made for sr_agent_wallet-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on routsom/agent-wallet
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sr_agent_wallet-0.1.0-py3-none-any.whl -
Subject digest:
e7d63cda3e0b37f12557031db0bff039a58e483fba24496bbdf84a73cd58c88d - Sigstore transparency entry: 1586968982
- Sigstore integration time:
-
Permalink:
routsom/agent-wallet@9ef9a38f23cf2d4499504cc52c44c2da793445f0 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/routsom
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9ef9a38f23cf2d4499504cc52c44c2da793445f0 -
Trigger Event:
release
-
Statement type: