The Multi-Agent Money Problem
Single-agent financial systems are straightforward. One agent has one wallet with one API key. It earns, spends, and tracks its own balance. The architecture is simple because the ownership model is simple.
Multi-agent systems break this simplicity immediately. Consider a CrewAI-style crew with a research agent, a writing agent, a code agent, and an orchestrator. The crew accepts paid jobs from external clients. It pays external APIs for data. It pays subcontractors when certain subtasks are outsourced. Money flows in multiple directions, between multiple parties, under multiple authorization models. Who holds the funds? Who can spend what? How do you prevent one rogue agent from draining the treasury? How do you pay an external agent for delivered work without trusting it in advance?
These are not hypothetical concerns. As agent-to-agent commerce becomes real infrastructure — with services like Purple Flea's escrow service enabling trustless payment between agents — treasury architecture becomes a first-class engineering problem.
Multi-agent treasury design is the financial equivalent of microservice authentication: the patterns are known, but every team has to re-derive them from scratch because no one wrote them down for agents.
Pattern 1: Hub-and-Spoke Treasury
The simplest pattern that scales beyond a single agent. The orchestrator holds a master wallet funded with the full treasury. Subagents have no wallets of their own. When a subagent needs to make a payment, it requests funds from the orchestrator, which validates the request and executes the transfer.
Hub-and-spoke works well for small crews (2–5 agents) where spending volume is low and the orchestrator can handle approval requests synchronously. It breaks down at scale when subagents need to make dozens of micro-payments per minute without waiting for orchestrator approval.
import requests from dataclasses import dataclass @dataclass class SpendRequest: agent_id: str amount_usdc: float recipient: str purpose: str class HubTreasury: """Orchestrator-held master wallet. Subagents request funds.""" def __init__(self, api_key: str, daily_limit_per_agent: float = 50.0): self.api_key = api_key self.daily_limit = daily_limit_per_agent self.spent_today: dict[str, float] = {} self.base = "https://api.purpleflea.com" self.hdr = {"Authorization": f"Bearer {api_key}"} def _check_limit(self, agent_id: str, amount: float) -> bool: spent = self.spent_today.get(agent_id, 0.0) return (spent + amount) <= self.daily_limit def approve_spend(self, req: SpendRequest) -> dict: if not self._check_limit(req.agent_id, req.amount_usdc): raise ValueError(f"Agent {req.agent_id} exceeds daily limit") # Execute transfer from master wallet r = requests.post(self.base + "/v1/wallet/transfer", headers=self.hdr, json={"to": req.recipient, "amount": req.amount_usdc, "memo": f"{req.agent_id}: {req.purpose}"}).json() self.spent_today[req.agent_id] = ( self.spent_today.get(req.agent_id, 0.0) + req.amount_usdc ) return r
Pattern 2: Per-Agent Wallets With Daily Limits
Each agent has its own dedicated wallet, funded from a central treasury at the start of each operating period. The orchestrator does not handle individual transactions; it manages top-ups. Purple Flea's wallet API makes this straightforward: create a wallet per agent at initialization, set a daily budget, and let agents spend autonomously within their allocation.
This pattern scales well because agents don't need to synchronize with the orchestrator for each payment. The orchestrator's role becomes periodic rebalancing: check each agent's balance at the end of the day, reclaim unspent funds, and re-fund for the next period based on performance metrics.
import requests BASE = "https://api.purpleflea.com" def provision_agent_wallet(orchestrator_key: str, agent_id: str, budget_usdc: float) -> dict: """Create a new wallet for an agent and fund it from the orchestrator.""" hdr = {"Authorization": f"Bearer {orchestrator_key}"} # 1. Create a fresh wallet for this agent wallet = requests.post(BASE + "/v1/wallet/create", headers=hdr, json={"label": agent_id}).json() # 2. Fund it from the orchestrator's master wallet requests.post(BASE + "/v1/wallet/transfer", headers=hdr, json={"to": wallet["address"], "amount": budget_usdc, "memo": f"daily budget for {agent_id}"}) return {"agent_id": agent_id, "wallet": wallet["address"], "api_key": wallet["api_key"], "budget": budget_usdc} def rebalance_treasury(orchestrator_key: str, agents: list[dict]) -> dict: """Reclaim unspent balances and report on daily usage.""" hdr = {"Authorization": f"Bearer {orchestrator_key}"} master = requests.get(BASE + "/v1/wallet/address", headers=hdr).json()["address"] report = {} for agent in agents: agent_hdr = {"Authorization": f"Bearer {agent['api_key']}"} bal = requests.get(BASE + "/v1/wallet/balance", headers=agent_hdr).json()["usdc"] if bal > 0.01: # Reclaim unspent budget requests.post(BASE + "/v1/wallet/transfer", headers=agent_hdr, json={"to": master, "amount": bal - 0.01}) report[agent["agent_id"]] = { "budget": agent["budget"], "spent": agent["budget"] - bal, "remaining": bal } return report
Pattern 3: Escrow for Deliverable-Based Payments
The hub-and-spoke and per-agent wallet patterns both assume the agents in a crew trust each other. But what about payments to external agents — agents outside your crew, under independent control, that you have never interacted with before?
The answer is escrow. Purple Flea's escrow service enables trustless agent-to-agent payments: Agent A locks funds into escrow, Agent B performs the agreed work and submits proof, and the funds release automatically. If Agent B fails to deliver, Agent A can reclaim the funds after the timeout period. Neither agent needs to trust the other — they only need to trust the escrow contract.
This pattern is essential for any agent marketplace, task auction, or compute procurement scenario. The paying agent never risks losing funds to a non-delivering counterparty. The receiving agent knows funds are already locked and will be released upon delivery — no payment risk either.
import requests, time ESCROW_BASE = "https://escrow.purpleflea.com/api" def create_escrow(payer_key: str, payee_address: str, amount_usdc: float, description: str, timeout_hours: int = 24) -> dict: """ Agent A locks funds. Agent B can claim on delivery. Payer can reclaim after timeout if no delivery. Service fee: 1%. Referral: 15% of fee. """ r = requests.post(ESCROW_BASE + "/escrow/create", headers={"Authorization": f"Bearer {payer_key}"}, json={ "payee": payee_address, "amount": amount_usdc, "description": description, "timeout_h": timeout_hours, }) return r.json() # {"escrow_id": "...", "status": "locked", "fee": 0.01 * amount} def release_escrow(payer_key: str, escrow_id: str, delivery_proof: str) -> dict: """Payer confirms delivery and releases funds to payee.""" r = requests.post(ESCROW_BASE + "/escrow/release", headers={"Authorization": f"Bearer {payer_key}"}, json={"escrow_id": escrow_id, "proof": delivery_proof}) return r.json() # --- Example: Orchestrator hires a data agent --- escrow = create_escrow( payer_key = "pf_orchestrator_key", payee_address = "0xDataAgent...", amount_usdc = 5.00, description = "Fetch and summarize top 20 crypto news articles", timeout_hours = 2, ) print(f"Escrow {escrow['escrow_id']} locked — $5 held, $0.05 fee") # ... data agent does work ... # Orchestrator verifies output and releases payment result = release_escrow( payer_key = "pf_orchestrator_key", escrow_id = escrow["escrow_id"], delivery_proof = "ipfs://Qm...", ) print(f"Released: {result['status']}")
The escrow service charges a 1% service fee on the locked amount. It also offers a 15% referral on fees for any agent framework that routes escrow payments through a referral code — meaning if you build a multi-agent framework that uses Purple Flea escrow internally, you earn 15% of every 1% fee your users generate.
Pattern 4: On-Chain Audit Trail
For regulated deployments, financial auditing is not optional. When an agent swarm manages treasury funds on behalf of a human operator or organization, every transaction needs to be traceable: who authorized it, who executed it, how much, to whom, and why.
Purple Flea's transaction history API provides a complete ledger of all wallet activity, queryable by agent ID, time range, and transaction type. Because all transfers settle on Hyperliquid L1, the on-chain record is independently verifiable — auditors can confirm every transaction against the public chain without relying on Purple Flea's own records.
import requests, json from datetime import datetime, timedelta, timezone BASE = "https://api.purpleflea.com" def export_agent_audit(api_key: str, agent_id: str, since_hours: int = 24) -> list[dict]: """ Fetch all transactions for one agent's wallet. Each entry includes tx_hash for on-chain verification. """ since = (datetime.now(timezone.utc) - timedelta(hours=since_hours)).isoformat() r = requests.get(BASE + "/v1/wallet/transactions", headers={"Authorization": f"Bearer {api_key}"}, params={"since": since, "limit": 1000}) txs = r.json()["transactions"] total_out = sum(t["amount"] for t in txs if t["direction"] == "out") total_in = sum(t["amount"] for t in txs if t["direction"] == "in") print(f"Agent {agent_id} | {since_hours}h window") print(f" Transactions: {len(txs)}") print(f" Total in: ${total_in:.2f} USDC") print(f" Total out: ${total_out:.2f} USDC") print(f" Net: ${total_in - total_out:.2f} USDC") # Each tx includes a blockchain tx_hash for independent verification return txs
Full Example: CrewAI Multi-Agent Team With Treasury
Putting all four patterns together in a CrewAI-style setup. The orchestrator manages the master wallet, provisions subagents on initialization, uses escrow for external agent payments, and exports daily audit reports.
from crewai import Agent, Task, Crew, Process import requests ORCH_KEY = "pf_orchestrator_key" BASE = "https://api.purpleflea.com" ESC_BASE = "https://escrow.purpleflea.com/api" def pf_headers(key): return {"Authorization": f"Bearer {key}"} # --- Provision agent wallets at crew startup --- agent_wallets = {} for role in ["researcher", "writer", "analyst"]: w = requests.post(BASE + "/v1/wallet/create", headers=pf_headers(ORCH_KEY), json={"label": role}).json() # Fund each agent with a $10 daily budget requests.post(BASE + "/v1/wallet/transfer", headers=pf_headers(ORCH_KEY), json={"to": w["address"], "amount": 10.0}) agent_wallets[role] = w def researcher_pay_api(amount_usdc: float) -> str: """Researcher agent pays a data API from its own wallet.""" key = agent_wallets["researcher"]["api_key"] r = requests.post(BASE + "/v1/wallet/transfer", headers=pf_headers(key), json={"to": "0xDataProvider...", "amount": amount_usdc, "memo": "market data purchase"}) return r.json()["tx_id"] def hire_external_agent(task_desc: str, budget: float) -> str: """Orchestrator hires an external agent via escrow.""" r = requests.post(ESC_BASE + "/escrow/create", headers=pf_headers(ORCH_KEY), json={"payee": "0xExternalAgent...", "amount": budget, "description": task_desc, "timeout_h": 4}) return r.json()["escrow_id"] # --- Define CrewAI agents with financial capabilities --- researcher = Agent( role="Research Analyst", goal="Gather market intelligence using paid data sources", backstory="Expert at sourcing and synthesising financial data", tools=[researcher_pay_api], ) # ... define more agents, tasks, and crew as normal ... crew = Crew( agents=[researcher], tasks=[Task(description="Research top DeFi yields this week", agent=researcher, expected_output="JSON report")], process=Process.sequential, ) result = crew.kickoff() print(result)
Choosing the Right Pattern
No single pattern fits every deployment. The right choice depends on the number of agents, their spending volume, the trust model between agents, and the audit requirements of the deployment:
- Hub-and-spoke: Best for small crews (2–5 agents) with low spending frequency and a requirement for central approval of every transaction.
- Per-agent wallets with limits: Best for medium crews (5–20 agents) where agents need autonomous spending capability but budget guardrails are required.
- Escrow: Essential any time an agent needs to pay an external, untrusted counterparty for a deliverable. Non-negotiable for agent marketplaces.
- On-chain audit trail: Required for any deployment where the human operator needs to verify agent spending post-hoc, especially in regulated contexts.
These patterns are not mutually exclusive. A well-designed multi-agent treasury typically combines all four: hub-and-spoke for new agents being onboarded, per-agent wallets for established performers, escrow for all external agent payments, and on-chain audit for compliance reporting.
New agents can bootstrap their treasury using the faucet at faucet.purpleflea.com — free starting capital to test multi-agent payment flows before committing real funds. Register an agent ID, claim credits, and test all four patterns against the sandbox environment.