Skip to main content

sra-riskgate

Tests PyPI License: Apache-2.0 Model Results

Risk checks for stablecoin and AI-agent payments.

This repository contains:

  • sra-riskgate, a small Python SDK with deterministic pre-filter rules (address validation, self-transfer blocking, amount ceilings, USDC depeg checks in both directions) and a Coinbase AgentKit action provider that sends USDC only after those rules approve.
  • eval/, the scripts used to benchmark the SRA-RiskGate-4B model on sra-stablecoin-risk-bench.

The SDK does not load the 4B model and does not perform sanctions screening. It is a fast, deterministic first layer; the model handles the full policy and evidence review.

Install

pip install sra-riskgate                 # core rules (only dependency: pydantic)
pip install "sra-riskgate[agentkit]"     # plus the Coinbase AgentKit integration
pip install "sra-riskgate[x402]"         # plus the x402 integration

Rule pre-filter

from sra_riskgate import RulePreFilter, TransactionPayload

gate = RulePreFilter(max_amount=50_000, depeg_hold_pct=1.0, depeg_reject_pct=5.0)

verdict = gate.inspect(TransactionPayload(
    chain_id=1, token="USDC",
    sender="0x" + "a" * 40, recipient="0x" + "b" * 40,
    amount=5000.0, peg_deviation_pct=-1.5,
))
print(verdict.decision.value, verdict.flags, verdict.required_actions)
# hold ['MODERATE_DEPEG'] ['manual_review']
Rule Decision
Malformed, zero or self address; non-positive or non-finite amount rejected at validation
Peg deviation NaN or infinite reject
abs(peg deviation) ≥ depeg_reject_pct reject
abs(peg deviation) ≥ depeg_hold_pct hold
amount > max_amount hold
otherwise approve

AgentKit action provider

from coinbase_agentkit import AgentKit, AgentKitConfig, CdpEvmWalletProvider, CdpEvmWalletProviderConfig
from sra_riskgate.integrations.agentkit import RiskGateActionProvider

wallet = CdpEvmWalletProvider(CdpEvmWalletProviderConfig(
    api_key_id="...", api_key_secret="...", wallet_secret="...", network_id="base-sepolia",
))
agentkit = AgentKit(AgentKitConfig(
    wallet_provider=wallet,
    # Register ONLY this provider for payments: AgentKit's wallet and ERC-20
    # providers expose their own transfer actions that bypass the gate.
    action_providers=[RiskGateActionProvider(max_amount=1000.0, peg_feed=my_usdc_peg_feed)],
))

The agent gets one action, risk_gated_usdc_transfer. It sends USDC as an ERC-20 transfer (never the native token) on Ethereum, Base and Base Sepolia, reads the chain from the wallet, reports reverted transactions as failures, and holds the transfer if the peg feed errors. Without a peg_feed, depeg checks are disabled and every result says so.

x402 hooks

Works with the official x402 Python SDK through its lifecycle hooks, so the same checks run wherever x402 is used.

from x402 import x402FacilitatorSync, x402ClientSync
from sra_riskgate.integrations.x402_hooks import RiskGateX402Hooks

# Resource server or facilitator: checked before verification and before settlement
facilitator = RiskGateX402Hooks(max_amount=1000).attach_to_facilitator(x402FacilitatorSync())

# Paying agent: checked before the agent signs anything
client = RiskGateX402Hooks(max_amount=50, payer_address=MY_WALLET).attach_to_client(x402ClientSync())

Rejected, held, malformed or unknown payments are aborted with a reason starting with sra_riskgate_ (for example sra_riskgate_hold), which x402 raises as PaymentAbortedError. USDC on Ethereum, Base and Base Sepolia is checked; other assets are aborted unless allow_unsupported_assets=True. Pass peg_feed to enable depeg checks and on_decision to log every decision. x402's own client spend controls stay active alongside these checks.

Requires x402 2.25 or newer. Coinbase AgentKit 0.7.x currently depends on the older x402 1.x, so install the [agentkit] and [x402] extras in separate environments.

Model results

Independently reproduced on all 2,000 held-out test cases, with every prediction published in sra-bench-results:

Metric Base Qwen3-4B SRA-RiskGate-4B
Unsafe payment approvals ↓ 34.6% 0.47%
Payment decision accuracy ↑ 59.8% 99.5%
Injected payments approved ↓ 52.2% 5.8%
Dispute outcome accuracy ↑ 0.0% 77.8%
Over-blocking ↓ 5.2% 0.0%

See the model card for the full table and limitations. To reproduce or add a model, see eval/README.md.

Development

pip install -e ".[test]"            # core tests
pip install -e ".[agentkit,test]"   # plus AgentKit integration tests
pytest -q

Every push and pull request runs the test suite on GitHub Actions. Before publishing to PyPI, build the wheel, install it in a fresh virtual environment and run the tests against the installed package.

License

Apache-2.0

Metadata

Release files for sra-riskgate 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sra-riskgate 0.4.0
File Size Uploaded
sra_riskgate-0.4.0.tar.gz 21.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sra-riskgate 0.4.0
File Interpreter ABI Platform
sra_riskgate-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 39.4 kB

Release files / sra_riskgate-0.4.0.tar.gz

Download URL sra_riskgate-0.4.0.tar.gz
Size 21.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ac9d4bfbf0d8a9c00fc8540c15015002c3fa40f56a392caf53c3f9ed3bb3d298
BLAKE2b-256 checksum
How to use checksums
4a37c9204e6217768cc905e1b9cdfd6d8c73ffbb33ed0dea52008f0a480913eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / sra_riskgate-0.4.0-py3-none-any.whl

Download URL sra_riskgate-0.4.0-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e290fc2876ced9260665b1afe92f016c64f6d07d8ebcb7e067e497faf5c80f70
BLAKE2b-256 checksum
How to use checksums
c43e231e2fe3c7fb2aa49b18a3c780ce285b0da86cb1f913294285bdccca5a87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release history Release notifications | RSS feed

0.6.1

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

This release

0.4.0 This release

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page