💰 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
Metadata
Release files for sr-agent-wallet 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sr_agent_wallet-0.1.0.tar.gz | 42.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sr_agent_wallet-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 79.6 kB
Release files / sr_agent_wallet-0.1.0.tar.gz
| Download URL | sr_agent_wallet-0.1.0.tar.gz |
|---|---|
| Size | 42.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
57b6b075db6cada631a40711fe6a3037a2574ef24026a734b74a3e2136642d4c
|
|
BLAKE2b-256 checksum How to use checksums |
a523e42c2e972a02ac8a1fe60ea078ae9edf5395f4d38985d7e7440f93e9282c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 20, 2026.
Transparency logRelease files / sr_agent_wallet-0.1.0-py3-none-any.whl
| Download URL | sr_agent_wallet-0.1.0-py3-none-any.whl |
|---|---|
| Size | 36.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e7d63cda3e0b37f12557031db0bff039a58e483fba24496bbdf84a73cd58c88d
|
|
BLAKE2b-256 checksum How to use checksums |
44bca902d7bb26d499638bc276b74bdb3165f979d12c207340be47cd638e0aee
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 20, 2026.
Transparency log