A spend firewall for your CrewAI crew
What is a spend firewall for CrewAI?
Give your CrewAI crew a spend firewall as a BaseTool. Every agent purchase is approved, blocked, or flagged against your rules.
TL;DR: Give your CrewAI crew a spend firewall as a BaseTool. Every agent purchase is approved, blocked, or flagged against your rules.
When one agent in your crew holds the purse, a bad merchant or a runaway task can drain it. sipi.bot becomes a BaseTool the crew must consult before spending.
Expose the firewall as a typed BaseTool with a Pydantic args_schema. The crew calls it before any purchase, and you put the obligation in the agent's backstory.
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
from sipi_guard import evaluate
class SpendInput(BaseModel):
amount: float = Field(..., description="Amount in USD")
merchant: str = Field("", description="Who is being paid")
category: str = Field("", description="compute | api | ads | goods")
class SpendGuardTool(BaseTool):
name: str = "spend_guard"
description: str = "Check a purchase BEFORE spending. Returns APPROVED, BLOCKED, or FLAGGED."
args_schema: type[BaseModel] = SpendInput
def _run(self, amount: float, merchant: str = "", category: str = "") -> str:
d = evaluate(amount, merchant, category)
if d["decision"] == "BLOCKED":
return f"BLOCKED: {d['reason']}. Do not proceed."
if d["decision"] == "FLAGGED":
return f"FLAGGED for human approval: {d['reason']}."
return f"APPROVED: safe to spend ${amount:.2f} at {merchant}."
Add SpendGuardTool() to the agent that holds the budget and add to its backstory: "You must call spend_guard before any purchase and obey its decision." For hard enforcement, wrap the actual purchase tool the same way.
Crew-wide spend policy
Because every agent hits the same firewall, your daily cap and velocity limits apply across the whole crew, not per agent. One runaway member can't blow the shared budget.
Frequently asked
How do I enforce the firewall across a whole crew?
sipi.bot tracks daily totals and velocity globally, so a shared budget and runaway-loop protection apply across every agent in the crew, not per individual agent.
Can I make spend_guard mandatory, not just suggested?
Yes. Put the obligation in the agent backstory for soft enforcement, and for hard enforcement wrap the real purchase tool so it calls the firewall internally and refuses on a blocked decision.
Does this need CrewAI Enterprise?
No. It works with open-source CrewAI. sipi_guard.py is a zero-dependency client; only the BaseTool wrapper uses CrewAI.