Skip to main content

Spendpol โ€” AI Spend Protocol. Delegated spending governance for autonomous AI agents.

Project description

๐Ÿ” Spendpol

AI Spend Protocol โ€” Governance for autonomous agent spending.

License: MIT Python 3.10+ Tests

Spendpol is an open protocol that sits between AI agents and payment systems. It answers one question:

"Should this agent be allowed to make this expenditure?"

Spendpol does not move money. It governs whether money should move.


Why Spendpol?

AI agents are calling APIs, purchasing compute, and consuming paid services. But spending controls are stuck in the human era: hardcoded API keys, manual approval, cloud budget alerts.

As agents scale from 1 to 1,000 and delegate tasks to sub-agents, the uncontrolled spending surface grows exponentially. Spendpol provides the governance layer.

Agent Logic โ†’ [Spendpol] โ†’ Payment Execution
                 โ”‚
                 โ”œโ”€โ”€ Is this agent authorized?
                 โ”œโ”€โ”€ Within spending limits?
                 โ”œโ”€โ”€ Anomaly detected?
                 โ””โ”€โ”€ Audit logged โœ“

Install

pip install spendpol

Quick Start

from spendpol import SpendpolClient

client = SpendpolClient()

# Human grants spending authority to an agent
client.grant(
    delegator="user:john@acme.com",
    delegatee="agent-research",
    max_per_transaction=1.00,
    max_daily=10.00,
    max_monthly=200.00,
    allowed_vendors=["openai", "anthropic"],
    allowed_actions=["api_call"],
)

# Agent requests permission to spend
verdict = client.check_intent(
    agent_id="agent-research",
    vendor="openai",
    action="api_call",
    amount=0.03,
    purpose="Generate embeddings for ticket #4521",
)

if verdict.allowed:
    result = call_openai_api()  # Your payment execution
    client.log_receipt(verdict, actual_amount=0.028)
elif verdict.denied:
    print(f"Blocked: {verdict.evaluations[-1].detail}")

CrewAI Integration

from spendpol.crewai import SpendpolCrewMiddleware

asp = SpendpolCrewMiddleware(
    delegator="user:john@acme.com",
    default_daily_limit=10.00,
    allowed_vendors=["openai", "anthropic"],
)

# Decorator: one line to control any tool's spending
@asp.controlled(vendor="openai", action="api_call", cost_per_call=0.03)
def embedding_tool(text: str) -> list[float]:
    return openai.embeddings.create(input=text)

# Automatically: checks policy โ†’ executes โ†’ logs receipt
result = embedding_tool("Hello world")

Core Concepts

Concept What it does
SpendIntent Agent declares "I want to spend $X on Y"
PolicyVerdict Engine responds: allow / deny / escalate
SpendReceipt Records what actually happened
AuditQuery Anyone can inspect spending history
DelegationGrant Human gives agent permission with limits
Attenuation Sub-agents can only have fewer permissions, never more

What Spendpol Is NOT

  • Not a wallet โ€” holds no funds
  • Not a payment processor โ€” moves no money
  • Not a blockchain โ€” no consensus, no tokens
  • Not KYC/AML โ€” no identity verification
  • Not a legal entity โ€” agents have no personhood

Spendpol's regulatory surface is equivalent to a logging tool, not a financial service.

Architecture

spendpol/
โ”œโ”€โ”€ schemas.py             # Protocol message types
โ”œโ”€โ”€ delegation.py          # Delegation chains + attenuation
โ”œโ”€โ”€ wallet.py              # Non-custodial spending tracker
โ”œโ”€โ”€ policy.py              # Deterministic policy engine
โ”œโ”€โ”€ audit.py               # Append-only audit log
โ”œโ”€โ”€ validator.py           # Message validation + verification
โ”œโ”€โ”€ client.py              # High-level SDK
โ”œโ”€โ”€ crewai.py              # CrewAI middleware
โ”œโ”€โ”€ langgraph.py           # LangGraph middleware
โ”œโ”€โ”€ autogen.py             # AutoGen middleware
โ”œโ”€โ”€ schemas/               # JSON Schema definitions (Draft 2020-12)
โ”‚   โ”œโ”€โ”€ spend-intent.schema.json
โ”‚   โ”œโ”€โ”€ policy-verdict.schema.json
โ”‚   โ”œโ”€โ”€ spend-receipt.schema.json
โ”‚   โ”œโ”€โ”€ delegation-grant.schema.json
โ”‚   โ”œโ”€โ”€ audit-query.schema.json
โ”‚   โ””โ”€โ”€ cost-estimate.schema.json
โ”œโ”€โ”€ examples/              # Test vector payloads
โ”‚   โ”œโ”€โ”€ spend-intent.json
โ”‚   โ”œโ”€โ”€ policy-verdict-allow.json
โ”‚   โ”œโ”€โ”€ policy-verdict-deny.json
โ”‚   โ”œโ”€โ”€ spend-receipt.json
โ”‚   โ”œโ”€โ”€ delegation-grant.json
โ”‚   โ””โ”€โ”€ audit-query.json
โ”œโ”€โ”€ test_core.py           # 45 core tests
โ”œโ”€โ”€ test_langgraph.py      # 22 LangGraph tests
โ”œโ”€โ”€ test_autogen.py        # 23 AutoGen tests
โ””โ”€โ”€ WHITEPAPER.md          # Full protocol specification

Run Tests

pip install pytest
python -m pytest test_core.py test_langgraph.py test_autogen.py -v

Protocol Specification

Read the full WHITEPAPER.md for:

  • Complete message schemas with JSON examples
  • Delegation model and attenuation principle
  • Policy engine evaluation order
  • Anomaly detection specification
  • Trust and liability model
  • Audit role taxonomy

Roadmap

  • Core protocol (4 message types)
  • Delegation chains with attenuation
  • Deterministic policy engine
  • Anomaly detection (confidence-aware)
  • Audit log with role-based access
  • CrewAI integration
  • LangGraph integration
  • AutoGen integration
  • REST API server (spendpol-cloud)
  • Dashboard (spend analytics)
  • PyPI publish
  • Agent-to-agent commerce (Phase 1)

Contributing

Spendpol is an open protocol. Contributions welcome.

  1. Fork the repo
  2. Create your feature branch (git checkout -b feature/my-feature)
  3. Run tests (python -m pytest test_core.py test_langgraph.py test_autogen.py -v)
  4. Submit a PR

License

  • Python code (reference implementation): MIT
  • Protocol specification (WHITEPAPER.md, JSON Schemas): CC-BY-4.0

See DISCLAIMER.md for important legal notices.


Cloud computing gave machines compute. Spendpol gives machines governance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spendpol-0.1.0.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spendpol-0.1.0-py3-none-any.whl (35.3 kB view details)

Uploaded Python 3

File details

Details for the file spendpol-0.1.0.tar.gz.

File metadata

  • Download URL: spendpol-0.1.0.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for spendpol-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f8a4d4b9837c3493b5f35b3bcf5a8bb31977519ec2b5b6324e82222a495b01bc
MD5 9b3101582c312a8684177d6581487c84
BLAKE2b-256 b5b9d4d57c82fd8920f5ba2fe87e8ccb72b6a53a59d80c0a5f77bcc499817815

See more details on using hashes here.

File details

Details for the file spendpol-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: spendpol-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 35.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for spendpol-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 60ce523ffe8eeac0c7a9b372875226fc0e87e5799dbf7b34966076b81e3ae1e0
MD5 ba4410df26ed960a8d79b83e36da3b43
BLAKE2b-256 c9f959db174d8dc25e0fa19ee6b0afb74bdb63b2bdbe13c0a15d1ada97f6d2b5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page