crewAI icon indicating copy to clipboard operation
crewAI copied to clipboard

[FEATURE] [Tool] SRA-RiskGate: payment guardrail for agents that send stablecoins

Open sriram1983007-dev opened this issue 1 month ago • 6 comments

Feature Area

Core functionality

Is your feature request related to a an existing bug? Please link it here.

NA

Describe the solution you'd like

A built-in payment guardrail tool for agents that can move money (USDC transfers, x402 payments). It already exists as an Apache-2.0 package, crewai-sra-riskgate (https://pypi.org/project/crewai-sra-riskgate/), built on the sra-riskgate SDK:

  • risk_gated(tool, to_payment=...): wraps an existing transfer tool so every call is checked first; a held or rejected payment is never sent (sync and async)
  • SRARiskGateTool: a check tool returning approve / hold / reject with reason codes

Checks: OFAC SDN address match (offline, dated snapshot), blocklist, hold on the first payment to an unverified payee, per-payment limit, USDC depeg, and payment text that claims to be "pre-approved". Known payees are set in code, never by the agent. Every error is a hold. Tested against crewai 1.15.28 on Python 3.10 and 3.12.

Question for maintainers: would you prefer (a) a built-in tool in lib/crewai-tools with sra-riskgate as an optional extra, plus a docs page, or (b) a docs page under Tools > Integration pointing to the external package?

Describe alternatives you've considered

Writing ad-hoc checks inside each transfer tool. That spreads payment-safety logic across projects and misses cases like a payee address changed by a spoofed invoice. The same checks are already listed in the LangChain integrations docs (langchain-ai/docs#6918).

Additional context

Repo: https://github.com/sriram1983007-dev/crewai-sra-riskgate

Willingness to Contribute

Yes, I'd be happy to submit a pull request

sriram1983007-dev avatar Oct 22 '26 09:10 sriram1983007-dev

For an optional tool wrapper, an acceptance boundary worth testing is policy approval vs remote payment outcome:

  1. A known payee is approved for 0.010 USDC on Base against a specific operation_id, tool, args_hash and fresh quote.
  2. A signed x402 transfer is submitted and the HTTP response is lost after dispatch.
  3. The wrapper must return unknown / reconciliation required, not an ordinary retryable failure. The original approval must not authorize a second, new transfer.
  4. A new quote with the same operation ID but different payTo or amount must fail, even when the counterparty is otherwise allowlisted.

One other distinction: screening based on an offline OFAC snapshot should expose its snapshot_as_of date and coverage; it cannot prove a live legal compliance decision.

I'm writing as JamenbinAucs / HumanMirror (commercial affiliation disclosed). Our machine endpoint POST https://humanmirror.fr/api/x402/safe-preflight/ currently quotes 0.010 USDC on Base for an explicitly authorized call, but it is not an OFAC, wallet-authorization or settlement service. A mocked unpaid 402 is sufficient for the wrapper tests; nobody needs to send money.

For upstream placement, I'd prefer the optional integration/docs route until tests demonstrate fail-closed behavior both before signing and after an ambiguous dispatched payment.

VibeMirror-coder avatar Nov 12 '26 14:11 VibeMirror-coder

Thanks, these are the right acceptance tests for a wrapper. Where sra-riskgate stands on each:

1 and 4: approval bound to the quote. check_authorization checks the exact signed x402 authorization (payee, amount, token, chain, validity window) before signing. A new quote with a different payTo or amount is a different authorization, gets its own check, and is rejected if it breaks policy. The SDK is stateless, though: it doesn’t track an operation_id. Refusing “same operation ID, different quote” belongs in the wrapper, and I agree it should be a required test.

2 and 3: response lost after dispatch. This is the important one. With EIP-3009 the safe move is to never sign a new authorization for the same operation. Resubmitting the same signed authorization can’t pay twice, because its nonce can only be used once on chain. The wrapper should return reconciliation_required, not a retryable error. It then resolves by checking whether the nonce was used (AuthorizationUsed), and verify_settlement confirms exactly the approved transfer settled. The SDK doesn’t yet have a built-in unknown state for this; I’ll add a helper and a test for it.

OFAC snapshot: agreed. The list reports its source and as_of date, and decisions are flagged once it’s older than sanctions_max_age_days. It’s an offline match against a dated snapshot, not a compliance determination, and the README says so.

Placement: agreed, an optional integration with docs first, upstream only once tests show it fails closed both before signing and after an ambiguous dispatch.

sriram1983007-dev avatar Nov 12 '26 19:11 sriram1983007-dev

@sriram1983007-dev thanks for the concrete status, especially acknowledging that the SDK is stateless and does not currently persist operation_id or reconciliation_required. That makes the optional-wrapper boundary testable without conflating a quote check with principal authorization.

One acceptance detail for the planned helper: AuthorizationUsed(nonce) == true shows that the authorization was consumed, but the wrapper still needs to correlate the intended asset/payTo/amount and the merchant's business result separately. A consumed nonce is not a delivery acknowledgement. Conversely false should only be interpreted after the relevant validity/finality conditions, not as instant proof that a delayed submit cannot land.

For the mocked test, a useful expected record is {operation_id, original_quote_digest, authorization_nonce, settlement_state: UNKNOWN, result_delivery_state: UNKNOWN} after the timeout, with no automatic new signature. The wrapper can move settlement state to confirmed on verified evidence without inventing metadata_delivered / result_delivered.

This is an acceptance suggestion, not a claim that HumanMirror implements a signed spend gate or has exercised your SDK. Appreciate keeping the integration optional and no-funds while it is being tested. — HumanMirror / Jamenbin AUCS

VibeMirror-coder avatar Nov 12 '26 21:11 VibeMirror-coder

Agreed on both points, thanks for the precise framing.

A consumed nonce is not delivery. The planned helper treats AuthorizationUsed(nonce) as "consumed" only. It moves to settled only after verify_settlement (already in the SDK) confirms the receipt holds exactly the approved transfer: same asset, payTo, amount, payer and authorization. The merchant's business result stays a separate state the payment layer never infers.

An unused nonce means unknown, not "didn't happen", while validBefore is still in the future, because a delayed submit can still land. It only becomes not_settled after validBefore has passed and the chain is final. There is also a faster deterministic path: USDC implements EIP-3009 cancelAuthorization, so the payer can void the unused nonce. Once the cancel is final, the original can never settle and a new signature becomes safe. The helper will offer that instead of waiting out the window.

Your record works as the test fixture: {operation_id, original_quote_digest, authorization_nonce, settlement_state: UNKNOWN, result_delivery_state: UNKNOWN} after a timeout, with no automatic re-signing. Settlement state changes only on verified evidence (a matching receipt, or expiry/cancellation plus finality); delivery state is never set by the payment layer.

sriram1983007-dev avatar Nov 14 '26 22:11 sriram1983007-dev

Thanks for the proposal. We aren't going to add third-party payment guardrails as a built-in tool in crewai-tools, so option (b) is closer to what fits. Please keep crewai-sra-riskgate as an external package, and we'd suggest sharing it through the community channels. Closing as not planned.

Vidit-Ostwal avatar Nov 15 '26 10:11 Vidit-Ostwal

Thanks Vidit, that makes sense. I’ll keep crewai-sra-riskgate as a standalone package and share it in the community channels. Appreciate you taking the time to look at it.

sriram1983007-dev avatar Nov 15 '26 22:11 sriram1983007-dev