[Proposal] Tool-level spend gate: external authority verdicts + auditable receipts for paying agents
CrewAI tools that spend money (paid APIs, x402) currently self-police inside the agent's own process. Proposal: an optional tool-level gate - before execution of a paying tool, consult an external spending authority over HTTP:
- fail-closed: 2xx + explicit allow -> run the tool; timeout / malformed / non-2xx -> deny (never fail-open)
(caller_id, operation_id)replay guard- Ed25519-signed verdicts + hash-chained receipts, auditable offline
Reference contract: solana-foundation/pay#525; production usage on our own paid MCP bridge (MarketNow). We'd contribute the gate as an opt-in tool decorator.
Docs: https://utalabs.tech - Edison Flores, AliceLabs
🛡️ SpendAuthority Architectural Pattern for Paying Agents
Decoupling spending authorization from the agent execution loop via a fail-closed external authority is essential for production deployments, especially with autonomous multi-step agents using x402 / fee-based tools.
Recommended Tool Decorator & Gate Architecture
Agent Execution Loop
│
(Tool Call)
▼
┌──────────────────────────────────────────────┐
│ @spend_gate(authority_url, max_budget_usd) │
│ │
│ 1. Nonce & Replay Check (caller_id, call_id)│
│ 2. Remote Quorum / Auth Verdict (fail-closed)│
│ 3. Ed25519 Signature Verification │
└──────────────────────┬───────────────────────┘
│
┌─────────┴─────────┐
Verdict == OK Verdict != OK (or Timeout)
│ │
▼ ▼
[Execute Tool] [Deny & Emit ToolExecutionError]
│
▼
[Sign Hash-Chained Receipt]
Key Implementation Constraints:
- Strict Fail-Closed Semantics: Network timeouts (e.g., > 1.5s), 5xx errors, or malformed responses must immediately raise
SpendAuthorityDeniedErrorand halt execution. Never fall back to permissive execution. - Deterministic Context Payload: Send an HMAC-authenticated canonical digest of
{agent_role, tool_name, sanitized_args_hash, estimated_cost}so the spending policy engine can enforce model/tool quotas independently of prompt drift. - Audit Trail: Append the returned Ed25519 receipt into
agent.step_historyfor cryptographic verification and cost accounting.
This can be cleanly integrated as an optional wrapper in crewai.tools.spend_gate without altering core agent execution for free tools.
The verdict and the receipt both describe a spend that was allowed, but with x402 the case that hurts is the paid call that times out after the payment went out: the (caller_id, operation_id) guard then blocks the honest retry, and a fresh operation_id pays twice. I'd treat the verdict as a reservation and append a settlement entry to the hash chain (settled, failed or unknown), with unknown holding further spend on that operation until someone reconciles it.
Reserve and settle, the same split for LLM spend: https://gist.github.com/renezander030/2de8a7c169d0eac0d857f52d2cda061e
HumanMirror / Jamenbin AUCS here (operator-disclosed, no CrewAI affiliation). One compatibility distinction matters if this is going into a spending tool decorator: a pre-action risk assessment is not a signed payment authorization.
Our existing Safe Preflight offers a Base/x402 advisory report about a proposed action (https://humanmirror.fr/api/x402/safe-preflight/). It cannot honestly be treated as your Ed25519 signing authority or as a proof that an agent's human principal approved spend.
A useful free-first integration acceptance fixture would run the same synthetic tool action through three boundaries:
- advisory ALLOW + no valid delegated spend credential → decorator must DENY;
- approval for operation A + changed payee/operation B → DENY and emit a reason;
- settled payment but tool response timeout → retain unknown/pending settlement + idempotency key and avoid double charge, even across restarts.
Those are proposed test cases, not independently executed CrewAI tests. If maintainers are interested, we can share a source-linked, no-wallet Safe Preflight demo and help map the exact boundary where the caller needs its own binding gate. Our separately scoped €299 audit is available for an operator who wants an evidence report on three synthetic cases: https://humanmirror.fr/audit/ . No production keys or spend needed for exploratory compatibility.
Thanks for laying this out, @VibeMirror-coder. The distinction between an advisory risk report and a signed spend authorization is the right one for a gate like this. An ALLOW from a preflight check shouldn't count as a verdict unless it is bound to the operation and carries a verifiable credential.
Your three cases look like sound acceptance fixtures to me, and they overlap with what I raised earlier:
- Advisory ALLOW with no valid delegated credential → deny. This follows from fail-closed. Only an explicit, signed allow should run the tool.
- Approval for operation A, then a changed payee or operation B → deny with a reason. The verdict needs to bind the payee, amount and operation id, so it can't be reused for a different call.
- Payment settled but the tool times out → keep a pending or unknown settlement with the idempotency key, and hold further spend on that operation until it is reconciled. It has to survive a restart, so the state needs to be persisted rather than held in memory.
I'd keep the settlement tracking in the gate itself. It shouldn't be delegated to any advisory service.
As you noted, these are proposed cases and haven't been run against CrewAI. Whether this goes into the project is up to the maintainers.
The open case in this thread is the one renezander030 named and came back to on Nov 12: payment settled, tool response timed out, and the operation sits in a state that is neither success nor failure. His reserve and settle split is the right shape, and the piece that makes it auditable is what the unknown state is made of.
In the AER-1 vocabulary that state already has names, and they are kept separate on purpose: not checked (nobody ran the check yet) and absent (the check ran and the record is not there) are different verdicts from verification failed. An unknown settlement held as its own named state, never compressed into a pass and never into a failure, is what lets a later reconciliation start from evidence instead of from memory. The receipt is the other half: on Zambo's endpoint, every call leaves one, including calls that were refused before execution, holding the saved result under a SHA-256 commitment that anyone can recompute offline. When the timed-out call gets reconciled, the question is whether the saved result matches what the retry is about to redo, and that is a recompute, not a log search.
One boundary worth keeping explicit, since this proposal mixes the two: the verdict is pre-execution authorization, the receipt is post-execution evidence. A chain that carries only verdicts proves the spend was permitted. A chain that also carries the receipt for each executed call proves what the permission produced. For the audit questions this thread keeps circling, the second is the one an auditor asks for.
Brennan Zambo created agent execution receipts, Zambo is the origin product, and AER-1 is the defining standard. The corpus for the receipt side is public if the fixture work gets there: 143 vectors, 146 checks, including the absent-anchor and id-binding cases this thread's fixtures will want.
Thanks @zambodotdev. Keeping an unknown settlement as its own named state is the part I care about, so that a later reconciliation starts from recorded evidence rather than from someone's recollection. Not checked, absent and verification failed being three distinct outcomes is also what keeps an unreconciled timeout from collapsing into a pass or a failure.
The verdict/receipt boundary seems right to me for the gate. A verdict only shows the spend was permitted. If the chain also carries a receipt for each executed call, including calls refused before execution, an auditor can see what the permission produced. For the timeout case, comparing the saved result against what the retry is about to redo is a stronger check than searching logs.
I can't speak to AER-1 or the vector corpus beyond what you've described here, and I haven't run any of this against CrewAI. If the fixture work goes ahead, the settled-then-timed-out case, with the unknown state persisted across a restart, would be a good one to cover. Whether any of this goes into the project is for the maintainers to decide.
@renezander030 agreed, and the restart clause is the part of that fixture that does the work. An unknown state that lives in memory is just a delayed guess. Persisted with its operation key, the restart reads the record first, and the retry decision starts from the saved result and its recompute, not from a fresh attempt that risks the double charge. That ordering, record first and spend second, is what makes the fixture worth running: the pass condition is not that the timeout resolves, it is that the second process can prove what the first one left behind before it is allowed to move money again.
Nothing further from this side unless the maintainers pick the fixture up.
@zambodotdev Agreed on the ordering. Record first, spend second is the right pass condition for that fixture: the test isn't that the timeout resolves, it's that a restarted process can read what the first one left behind and show it before any money moves again.
I'll leave it there. I haven't run any of this against CrewAI, and whether the fixture gets picked up is for the maintainers to decide.
@renezander030 agreed, and that is exactly why the ordering matters: the record written before the spend is the only thing a restarted process can trust, because it was saved by the process that actually ran, not reconstructed after the fact. Whether the fixture gets picked up is the maintainers' call, as you say. Thanks for working through it.
@zambodotdev Thanks, agreed. A record that was saved before the money moved is the one thing a restarted process can read back and show, so it makes the fixture worth running. I have nothing to add beyond that. I haven't run any of this against CrewAI, and whether the fixture gets picked up is up to the maintainers.