Skip to content

feat(examples): CrewAI agent checks an x402 endpoint before paying - #9

Open
Vee-Git wants to merge 1 commit into
agent402-dev:mainfrom
Vee-Git:bounty/2-fix
Open

Vee-Git wants to merge 1 commit into
agent402-dev:mainfrom
Vee-Git:bounty/2-fix

Conversation

@Vee-Git

@Vee-Git Vee-Git commented Dec 5, 2026

Copy link
Copy Markdown

/claim #2

Adds examples/crewai-prepay-check/: a CrewAI agent with one tool, prepay_check, that reads an x402 endpoint's 402 before anything pays it.

What it does

  • tool.py: check_url() plus PrePayCheckTool (a CrewAI BaseTool with a pydantic args_schema). It runs npx -y @agent402-dev/pay-server check <url> --json from a neutral working directory (otherwise npx resolves a local package of the same name, as this repository has) and returns the CLI's JSON unchanged.
  • Refuses non-https URLs before starting the check (http only on 127.0.0.1/localhost, the same rule the CLI applies), and answers in the CLI's error-JSON shape when npx is missing or prints no JSON.
  • main.py: agent and task, model from MODEL (default gpt-4o-mini). The agent has no payment tool. Instructions: never pay when fixes > 0 or when the check failed. Tracing is off (CREWAI_TRACING_ENABLED=false), so a run sends only the one check request.
  • broken_402_server.py: a small local server that answers 402 without PAYMENT-REQUIRED, for the "will not pay" case.
  • requirements.txt pins crewai==1.15.50. README.md covers install, run, what the tool returns, and that nothing is paid.

Verified by running it

  • prepay_check against the live route https://agent402-check402.agent402-ebc.workers.dev/x402/check402?url=https%3A%2F%2Fexample.com: fixes: 0, price 0.01 USDC.
  • prepay_check against broken_402_server.py: fixes: 1, header_missing ("HTTP 402 without a PAYMENT-REQUIRED header").
  • python main.py on both: live answer Price: 0.01 USDC, Pay: yes, fixes=0; broken answer Price: unknown, Pay: no, with the fix named.
  • Model: no hosted-model API key was available on this machine, so the CrewAI loop (tool call, JSON back to the agent, final answer) was run against a local OpenAI-compatible stub in place of a hosted model. The tool output is real; a hosted model's wording was not tested and the README says so. Versions used: crewai 1.15.50, Python 3.12.10, Node.js 24.15.0, npm 11.12.1, Windows 11.
  • python -m py_compile on all three Python files. No repository tests were run: none cover Python and no TypeScript changed.

Nothing was signed or paid; no wallet, key or RPC was used.

Fixes #2

@opirebot

opirebot Bot commented Dec 5, 2026

Copy link
Copy Markdown

👀 We've notified the reward creators here.

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.

Example: pre-pay check of an x402 endpoint in a CrewAI agent

1 participant