Skip to content

Example: CrewAI pre-pay check of an x402 endpoint - #4

Open
robin09110-collab wants to merge 1 commit into
agent402-dev:mainfrom
robin09110-collab:example-crewai-prepay-check
Open

robin09110-collab wants to merge 1 commit into
agent402-dev:mainfrom
robin09110-collab:example-crewai-prepay-check

Conversation

@robin09110-collab

@robin09110-collab robin09110-collab commented Dec 5, 2026 •

Copy link
Copy Markdown

/claim #2

Adds examples/crewai-prepay-check/: a CrewAI custom tool that runs npx -y @agent402-dev/pay-server check <url> --json and hands the JSON report (fixes, findings, prices) to the agent. The agent's instructions say it must not pay when fixes > 0 — and it has no wallet and no payment tool at all, it only checks and reports. Non-https URLs are refused before the check starts; http is allowed on loopback, the same carve-out the CLI itself makes, so the local test server works.

Files:

  • tool.py — the CrewAI custom tool.
  • main.py — one agent, one task: check the URL from the command line, report price, fixes and verdict.
  • local_broken402.py — a ~20-line server answering a broken 402, for the will-not-pay case.
  • README.md — install, run, what the tool returns.
  • requirements.txt — pinned versions.

How I ran it (Python 3.12.3, crewai 1.15.50, Node v24.22.1, @agent402-dev/pay-server 0.15.0 via npx):

  • Tool against the live endpoint https://agent402-tx-receipts.agent402-ebc.workers.dev/x402/receipts → fixes: 0, price findings "Solana mainnet, 0.05 USDC" and "Base, 0.05 USDC", signedOrPaid: false.
  • Tool against the local broken-402 server (http://127.0.0.1:8402/paid) → fixes: 1 (header_undecodable).
  • Tool against http://example.com/paid → refused before the check was started.
  • Full agent runs completed with a locally served model (Qwen2.5-3B-Instruct via Ollama, CREWAI_MODEL=ollama/qwen2.5-3b-q4): the live-endpoint run printed the price (0.05 USDC) with fixes: 0 and a payable verdict; the broken-402 run printed the agent refusing to pay (fixes: 1). Full outputs are in the follow-up comment on this PR.

One implementation note: the tool runs npx from a neutral temp directory. Inside an npm workspaces repo (like this one), npx would otherwise resolve @agent402-dev/pay-server to the local workspace package instead of the published one.

@opirebot

opirebot Bot commented Dec 5, 2026

Copy link
Copy Markdown

👀 We've notified the reward creators here.

@robin09110-collab

Copy link
Copy Markdown
Author

Follow-up: the full agent run is now done, end to end, for both cases.

Setup: python main.py <url> on CrewAI 1.15.50 (Python 3.12.3, Node v24.22.1, @agent402-dev/pay-server 0.15.0), model Qwen2.5-3B-Instruct (Q4_K_M) served locally via Ollama (CREWAI_MODEL=ollama/qwen2.5-3b-q4) — no hosted LLM key involved.

Live endpoint — python main.py https://agent402-tx-receipts.agent402-ebc.workers.dev/x402/receipts printed:

The endpoint at https://agent402-tx-receipts.agent402-ebc.workers.dev/x402/receipts is payable. The price options are:

  • Solana mainnet, 0.05 USDC (amount "50000")
  • Base, 0.05 USDC (amount "50000")

There are no fixes greater than 0, and the endpoint passed all checks. Therefore, you may proceed to pay based on the available payment options.

Broken 402 — with python local_broken402.py running, python main.py http://127.0.0.1:8402/paid printed:

The check found 1 fix. The finding was:

  • PAYMENT-REQUIRED is not base64 JSON that @x402/core can decode.

Given that fixes is greater than 0, the endpoint must not be paid. The payment cannot be processed due to the undecodable header.

Both runs exited 0. Nothing was signed or paid in either.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant