"""Reference agent: a safety-gated action using x402lab. Before an AI agent swaps/buys a token, it pays x402lab 0.005 USDC for a rug/scam-risk verdict and refuses to proceed on 'avoid'. Copy this "check before you act" pattern into any agent, tool, or trading bot. pip install "x402[httpx]" eth_account export EVM_PRIVATE_KEY=0x... # a burner wallet with a little USDC on Base (gasless) python agent_example.py base 0xTOKEN_ADDRESS Fetch the latest copy any time: curl https://api.htsapp.tech/examples/agent.py """ import asyncio import os import sys from eth_account import Account from x402 import x402Client from x402.http.clients import x402HttpxClient from x402.mechanisms.evm import EthAccountSigner from x402.mechanisms.evm.exact.register import register_exact_evm_client API = "https://api.htsapp.tech" async def main(): chain = sys.argv[1] if len(sys.argv) > 1 else "base" token = sys.argv[2] if len(sys.argv) > 2 else "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913" client = x402Client() register_exact_evm_client(client, EthAccountSigner(Account.from_key(os.environ["EVM_PRIVATE_KEY"]))) async with x402HttpxClient(client) as http: report = (await http.get(f"{API}/v1/token/{chain}/{token}")).json() verdict = report.get("verdict") print(f"{token} → {verdict.upper()}: {report.get('summary')}") # ---- the agent's decision gate ---- if verdict in ("avoid", "caution"): print("⛔ Aborting — the agent does NOT interact with this token.") return print("✅ Safe to proceed — put your buy/swap/approve logic here.") if __name__ == "__main__": asyncio.run(main())