AgentMolt — Kill Switch & Budget Control for AI Agents
Monitor, budget-cap, and kill-switch your AI agents. Works standalone or with OpenAI/Anthropic/LangChain/CrewAI.
Install
pip install agentmolt
Quick Start — Try It Now (No API Key Needed)
from agentmolt import ACP, AgentBudget
# Create a local control panel (no API key = local-only mode)
panel = ACP()
# Register an agent with a $5 budget
panel.register("my-agent", budget=AgentBudget(max_cost_usd=5.00))
# Simulate agent making API calls
for i in range(10):
try:
state = panel.log("my-agent", model="gpt-4o", tokens=1000, cost=0.80)
print(f"Call {i+1}: ${state.total_cost_usd:.2f} spent, alive={panel.is_alive('my-agent')}")
except Exception as e:
print(f"Call {i+1}: KILLED — {e}")
break
Output:
Call 1: $0.80 spent, alive=True
Call 2: $1.60 spent, alive=True
Call 3: $2.40 spent, alive=True
Call 4: $3.20 spent, alive=True
Call 5: $4.00 spent, alive=True
Call 6: $4.80 spent, alive=True
Call 7: KILLED — Agent 'my-agent' killed: cost $5.60 exceeded budget $5.00
The agent is automatically killed when it exceeds its budget. No more runaway costs.
Kill Switch
from agentmolt import ACP
panel = ACP()
panel.register("research-bot")
# Check if agent is alive
print(panel.is_alive("research-bot")) # True
# Kill it manually
panel.kill("research-bot", reason="suspicious activity")
print(panel.is_alive("research-bot")) # False
# Any future calls raise AgentKilledException
try:
panel.log("research-bot", model="gpt-4o", tokens=100, cost=0.01)
except Exception as e:
print(f"Blocked: {e}")
# Revive if needed
panel.revive("research-bot")
print(panel.is_alive("research-bot")) # True
Budget Enforcement
Set limits on cost, tokens, or number of calls:
from agentmolt import ACP, AgentBudget
panel = ACP()
panel.register("writer-agent", budget=AgentBudget(
max_cost_usd=10.00, # Kill at $10 spent
max_tokens=100_000, # Kill at 100K tokens
max_calls=50, # Kill after 50 API calls
alert_at_pct=0.8, # Trigger alert at 80% of any limit
))
Callbacks — Get Notified
def on_kill(agent_id):
print(f"🚨 ALERT: {agent_id} was killed!")
def on_alert(agent_id, pct):
print(f"⚠️ WARNING: {agent_id} at {pct:.0%} of budget")
panel = ACP(
on_kill=on_kill,
on_alert=on_alert,
)
panel.register("spender", budget=AgentBudget(max_cost_usd=1.00, alert_at_pct=0.5))
panel.log("spender", model="gpt-4o", tokens=500, cost=0.30)
# → nothing
panel.log("spender", model="gpt-4o", tokens=500, cost=0.30)
# → ⚠️ WARNING: spender at 60% of budget
panel.log("spender", model="gpt-4o", tokens=500, cost=0.50)
# → 🚨 ALERT: spender was killed!
# → raises AgentKilledException
Auto-Patch OpenAI (Zero Code Changes)
from agentmolt import ACP
from openai import OpenAI
panel = ACP()
client = OpenAI()
panel.patch_openai(client)
# Use OpenAI as normal — all calls are automatically monitored
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Hello"}]
)
# Check what happened
for agent_id, state in panel.all_agents().items():
print(f"{agent_id}: {state.total_calls} calls, ${state.total_cost_usd:.4f}")
Auto-Patch Anthropic
from agentmolt import ACP
import anthropic
panel = ACP()
client = anthropic.Anthropic()
panel.patch_anthropic(client)
# All Claude calls are now monitored automatically
Decorators
from agentmolt import monitor, budget, kill_switch
@budget("analyst", max_cost_usd=50.0)
@kill_switch("analyst")
@monitor("analyst")
def run_analysis():
# Your agent code here — automatically monitored
pass
CLI
# Scan current directory for AI agent patterns
acp scan
# Show status of monitored agents
acp status
# Kill a rogue agent
acp kill marketing-bot --reason "unauthorized API spend"
# Check version
acp version
Status Dashboard
Check all your agents at a glance:
panel = ACP()
panel.register("agent-a", budget=AgentBudget(max_cost_usd=10.0))
panel.register("agent-b", budget=AgentBudget(max_cost_usd=5.0))
panel.log("agent-a", model="gpt-4o", tokens=2000, cost=1.50)
panel.log("agent-b", model="claude-3", tokens=500, cost=0.30)
for agent_id, state in panel.all_agents().items():
status = "🟢 alive" if not state.killed else "🔴 killed"
print(f"{agent_id}: {status} | ${state.total_cost_usd:.2f} | {state.total_calls} calls")
agent-a: 🟢 alive | $1.50 | 1 calls
agent-b: 🟢 alive | $0.30 | 1 calls
Connect to AgentMolt Dashboard
For real-time monitoring, alerts, and team dashboards:
panel = ACP(api_key="your-api-key") # Get key at agentmolt.dev
Events are batched and sent every 5 seconds. Works offline — events are buffered and retried on failure.
How It Works
- Register agents with optional budgets
- Log every LLM call (or auto-patch OpenAI/Anthropic)
- Budget check on every call — kills agent if exceeded
- Kill switch — manual or automatic, blocks all future calls
- Events buffered and flushed to dashboard (if API key set)
No external dependencies required for local mode. Just pip install agentmolt and go.
Requirements
- Python 3.9+
- No required dependencies for local mode
- Optional:
openai,anthropicfor auto-patching - Optional:
httpxfor dashboard sync (included)
License
MIT — built by AgentMolt
Release files for agentmolt 0.2.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 | |
|---|---|---|---|
| agentmolt-0.2.0.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentmolt-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.8 kB
Release files / agentmolt-0.2.0.tar.gz
| Download URL | agentmolt-0.2.0.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
810d43f2fa16fb4969756ff2792633f875535cee191c9a7d6e77408810b96597
|
|
BLAKE2b-256 checksum How to use checksums |
0b9dc070996bdb1e8624fafd4263f510239bfe6d5d6a9eb85c940ad4c0e4d617
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / agentmolt-0.2.0-py3-none-any.whl
| Download URL | agentmolt-0.2.0-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3247be71918402ef39155d1cb39fe078c3589b55abaf197ddb71f658ee3fa69d
|
|
BLAKE2b-256 checksum How to use checksums |
60d0d8e2a568d58e8778eadead498bbcd4a0f641478c8bc284eab8883e40ca8a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|