Repository navigation
Example: pre-pay check of an x402 endpoint in a CrewAI agent - #5
Open
IlhamEl777 wants to merge 1 commit into
Open
IlhamEl777 wants to merge 1 commit into
IlhamEl777 wants to merge 1 commit into
Conversation
Custom CrewAI tool that runs `pay-server check <url> --json` before anything pays: returns fixes/findings/price to the agent, refuses non-https URLs before starting the CLI, and the agent's instructions say do not pay when fixes > 0. Includes a local broken-402 server for the negative demo. Nothing is signed or paid.
|
👀 We've notified the reward creators here. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
/claim #2
What this adds
examples/crewai-prepay-check/— a runnable CrewAI example that checks an x402 paid endpoint before anything pays for it, as asked in #2:tool.py— a CrewAI custom tool (check_x402_endpoint) that runsnpx -y @agent402-dev/pay-server check <url> --jsonand returns the JSON report (fixes,findingsincl. the price,signedOrPaid) to the agent. One request, no payment header, nothing signed or paid, no key read. Non-https URLs are refused before the CLI is started; the only exception is http on localhost/127.0.0.1 (which the CLI itself also allows) so the local demo below can run.main.py— one agent + one task. The agent's instructions say explicitly: report the price, and do not pay whenfixes > 0. Model is CrewAI's default, overridable viaCREWAI_EXAMPLE_MODEL; an LLM key for CrewAI is the only key involved.broken402.py— a ~20-line local server answering a broken 402 (noPAYMENT-REQUIREDheader) for the negative case.requirements.txt—crewai==1.15.50pinned.README.md— install, run, what the tool returns, and the line that nothing is paid.No payment code, payment rules/limits, keys, wallets or signing are touched.
How to run
What I ran (versions: Python 3.12.3, CrewAI 1.15.50, Node v24.22.1, pay-server 0.15.0 via npx)
Honest note on method: my sandbox has no LLM API key, so I could not do a full
Crew.kickoff()run. I verified everything else end-to-end: the crew/agent/task wiring builds with the tool attached, and I ran the tool itself (the component that does the checking and produces every field the agent's answer is built from) against both required cases:(a) Live x402 endpoint — the toolkit's own hosted paid check402 route (0.01 USDC), through the tool:
{ "url": "https://agent402-check402.agent402-ebc.workers.dev/x402/check402?url=https://example.com", "fixes": 0, "findings": [ { "level": "ok", "code": "header", "message": "PAYMENT-REQUIRED header decodes." }, { "level": "ok", "code": "price", "message": "accepts[0]: Solana mainnet, 0.01 USDC (amount \"10000\")." }, { "level": "ok", "code": "price", "message": "accepts[1]: Base, 0.01 USDC (amount \"10000\")." } ], "signedOrPaid": false }Price shown,
fixes: 0→ the agent's instructions say this is the payable case.(b) Broken local 402 —
broken402.pyonhttp://127.0.0.1:8402/paid, through the tool:{ "url": "http://127.0.0.1:8402/paid", "fixes": 1, "findings": [ { "level": "fix", "code": "header_missing", "message": "HTTP 402 without a PAYMENT-REQUIRED header." } ], "signedOrPaid": false }fixes: 1→ the agent's instructions make it state it will not pay, listing this finding.(c) Non-https refusal —
http://example.com/paidreturns a refusal report ("Refused: only https URLs are checked...",fixes: null) without the CLI being started, verified by the same test run.AI tools were used to write this, as the issue allows; the checks above were run by me on the versions listed.