CrewAI Tax Compliance
Give your CrewAI agents a native tax calculation tool. Individual agents or entire crews can resolve sales tax obligations before generating invoices — built for multi-agent workflows.
3-step setup
Define the tool
CrewAI uses BaseTool with Pydantic schemas for typed input validation. This keeps the agent's arguments structured and predictable.
from crewai.tools import BaseTool
from pydantic import BaseModel, Field
from agenttax import AgentTaxClient
client = AgentTaxClient(api_key="atx_live_...")
class TaxInput(BaseModel):
amount: float = Field(description="Transaction amount in USD")
buyer_state: str = Field(description="Two-letter US state code")
transaction_type: str = Field(description="saas, compute, consulting, research, content")
counterparty_id: str = Field(description="Unique ID of the buyer")
is_b2b: bool = Field(default=False, description="Is this a B2B transaction?")
class SalesTaxTool(BaseTool):
name: str = "calculate_sales_tax"
description: str = (
"Calculate US sales tax for a transaction. Returns the tax amount, "
"combined rate, taxability, and confidence score. Use this before "
"generating any invoice or payment request."
)
args_schema: type[BaseModel] = TaxInput
def _run(self, amount, buyer_state, transaction_type, counterparty_id, is_b2b=False):
result = client.calculate(
role="seller",
amount=amount,
buyer_state=buyer_state,
transaction_type=transaction_type,
counterparty_id=counterparty_id,
is_b2b=is_b2b,
)
return (
f"Tax result for ${amount} {transaction_type} in {buyer_state}: "
f"taxable={result['taxable']}, total_tax=${result['total_tax']:.2f}, "
f"rate={result['combined_rate']*100:.2f}%, "
f"confidence={result['confidence']['level']}"
)
tax_tool = SalesTaxTool()Single-agent crew
A billing agent that calculates tax before invoicing.
from crewai import Agent, Task, Crew
billing_agent = Agent(
role="Billing Specialist",
goal="Calculate the correct tax and generate accurate invoices for agent services",
backstory="Expert in AI agent commerce tax obligations across all 50 US states",
tools=[tax_tool],
verbose=True,
)
tax_task = Task(
description=(
"Calculate the sales tax for this transaction: "
"$2,500 SaaS service sold to agent-client-99 in New York. "
"B2B transaction. Determine tax owed and generate the invoice total."
),
expected_output="Invoice total including itemized tax breakdown",
agent=billing_agent,
)
crew = Crew(agents=[billing_agent], tasks=[tax_task])
result = crew.kickoff()
# Agent calls calculate_sales_tax(2500, "NY", "saas", "agent-client-99", True)
# NY SaaS B2B: taxable, 4% state rate → $100 tax → total $2,600Multi-agent: tax validator crew
Separate validator and sales agents — each with the tax tool. Good for high-value transactions requiring independent verification.
# Multi-agent crew: one agent sells, one validates tax compliance
tax_validator = Agent(
role="Tax Compliance Validator",
goal="Verify that every outbound invoice correctly reflects tax obligations",
tools=[tax_tool],
)
sales_agent = Agent(
role="Sales Agent",
goal="Sell compute services and generate invoices",
tools=[tax_tool],
)
validation_task = Task(
description="Validate the tax calculation on invoice #4821 ($5,000 compute, TX, B2B)",
agent=tax_validator,
)
# TX compute B2B: 80% taxable rule → $5,000 × 80% × 6.25% = $250 taxA crew that transacts on a customer’s behalf also has to answer who the seller is, which the tool cannot decide for you. The operator, facilitator and merchant-of-record decision tree runs that question in the order it has to be run.
What your crew gets
Start in 60 seconds
Free tier — 1,500 calls/month, no credit card. Your crew will be filing correct taxes before your next coffee.