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
โ”œโ”€โ”€ service.py             # Agent-to-agent commerce registry
โ”œโ”€โ”€ 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
โ”‚   โ”œโ”€โ”€ service-offer.schema.json
โ”‚   โ”œโ”€โ”€ service-quote.schema.json
โ”‚   โ””โ”€โ”€ service-result.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
โ”‚   โ”œโ”€โ”€ service-offer.json
โ”‚   โ”œโ”€โ”€ service-quote.json
โ”‚   โ””โ”€โ”€ service-result.json
โ”œโ”€โ”€ test_core.py           # 67 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.2.0.tar.gz (34.7 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.2.0-py3-none-any.whl (40.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for spendpol-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4e322084886db59f6320b7b523bae8eb40fe15bea7ef5a0337e5f7976d32fee6
MD5 616049af8825d8ee4bd1307a8cddd997
BLAKE2b-256 251a63efb7ca335b223a59340690d72eb3199ff4f9b307070507d88e68ee3d38

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spendpol-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 40.9 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d3f56adbbd44a278efd145f869f9573ea9d78813294127af2cced014609b6134
MD5 95a89579d8aa0159bdc532ed466201d3
BLAKE2b-256 c9b6175ba3fad55796e3ce6128cb296baffa0ec81c089b011297db1d94704818

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