Inspiration
AI agents are starting to spend money on their own: paying for APIs, buying data, placing trades. The tooling for giving an agent a wallet is getting good. The tooling for trusting it isn't. Most "safety" lives inside the prompt, which means one bad output can drain the wallet.
I wanted to build the opposite: an agent that's genuinely autonomous, but whose spending rules live somewhere the model can't touch. Prediction markets were the perfect test, because every decision has a price, a probability, and real money behind it.
What it does
Leash Agent trades Gemini prediction markets on its own, on an allowance you control.
- Reads the odds. It pulls live prices from Gemini's prediction markets API.
- Buys research. It pays $0.01 per report, in USDC over x402 on Arc, for live sentiment from X that Grok Bot gathers on a schedule. The same feed sells reports to any other agent, so the project both buys and sells data.
- Asks Claude for the real odds. Claude only estimates a probability and its confidence. It never holds keys and never decides how much to spend.
- Does the math. Plain code compares Claude's estimate to the market price, subtracts Gemini's fees, and only trades if the expected profit per contract clears a minimum and Claude is confident enough.
- Asks the rulebook. Every spend goes through a smart contract on Arc first. It enforces a per-request cap, a daily cap, an allowlist of markets, and human approval above a threshold, plus a kill switch. Small trades go through instantly. Big ones wait for you.
- Pings you. A QuickNode Stream watches the contract, and the moment the agent asks for approval, your Mac shows a notification. You approve or decline with one click on the dashboard, and the decision is recorded onchain.
The dashboard shows today's allowance as a single bar (spent, waiting for you, left), Claude's estimate vs. the market for every market over time, every call the agent made with its full reasoning, a live feed of contract events, and a market finder where you can search any Gemini market, ask Claude about it, and add it to the agent's watchlist.
How we built it
- Rules contract (Solidity, Hardhat) on Arc testnet:
AgentPolicyat0x18731C3e4dDe85e8D8fC14c67DFFe20e2e69B737. It holds the USDC budget. The agent's key can only request; only the owner's key can approve, change limits, pause, or withdraw. Every request, approval, and execution is an event. - Payments (Circle Gateway + x402 on Arc): the agent's research budget lives in a Circle Gateway balance that can only be refilled through a contract
TOPUPrequest. Research is paid per request with gasless, batched USDC nanopayments. - Research (Grok Bot): Grok Bot reads X on a schedule and submits structured reports (summary, sentiment score, confidence, source posts) to the feed server.
- Brain (Claude API): a structured estimate (probability, confidence, reasoning, one-line reason). The one-line reason is stored onchain with every request, so every trade has a public "why."
- Markets (Gemini Prediction Markets API): live odds from the public API, with paper, sandbox, and live trading modes.
- Events (QuickNode Streams): Arc testnet, Block with Receipts dataset, with a filter that keeps only the contract's 7 event types and drops everything else. Deliveries go to a webhook with HMAC signature verification.
- Dashboard (TypeScript, viem): a local-only server that signs owner actions, with a per-session token so no other website can click buttons for you.
- 41 automated tests across the contract, feed server, and agent, including running real Arc receipts through the QuickNode filter and a signed webhook.
Challenges we ran into
- Gemini trades happen off-chain, so a contract can't literally block an order. I made the contract the gatekeeper instead: the agent can't place an order without an
Approvedrequest onchain, and it records the Gemini order id afterward. That gives an honest, public audit trail rather than a fake guarantee. - My first x402 payment failed verification. Circle's library checks payments against mainnet by default, so testnet payments were rejected until I pointed the seller at the testnet verifier.
- Grok Bot couldn't reach my server, and it (sensibly) refuses to type secret keys into forms. I added a browser login: I log in once, and Grok Bot submits reports through the form in my logged-in Chrome without ever seeing the key.
- Gemini has over 10,000 active contracts, mostly sports, so looking up a market by scanning everything timed out. I switched to direct event lookups with a category-by-category fallback.
- Keeping the model away from the money. It was tempting to let Claude say "buy $40 of YES." Splitting it so Claude only estimates and plain math decides made the system easier to reason about and much easier to explain.
Accomplishments that we're proud of
- The whole loop works end to end, onchain: the agent asked the contract for budget, the contract approved and sent USDC, the agent paid for research with a real x402 payment on Arc, Claude read it, and the code decided.
- When it has no research, Claude says "I don't trust myself over the market," and the agent sits out. Cautious by design.
- Approving a trade is one click, and the approval itself is an onchain transaction with a reason attached.
- Every safety limit is enforced in a place the AI can't change.
What we learned
- Guardrails belong outside the model. Prompts are suggestions; contracts are rules.
- x402 makes paying per request feel like calling an API. Batched nanopayments on Arc make a $0.01 purchase actually make sense.
- Prediction markets are hard to beat. Prices already contain most of the information, so an honest agent passes on most markets. Fees alone wipe out small edges.
Event streams beat polling for anything a human needs to react to quickly.
Arc mainnet and real Gemini trades, starting with a small daily cap.
A track record: score Claude's estimates against how markets actually resolve, and only raise the allowance as the agent earns it.
List the research feed on Circle's Agent Marketplace so other agents can discover and buy it.
Voice approvals with ElevenLabs: "Want me to buy $40 of YES on the Fed hike?" "Yes."
Shared allowances: let a team or family set rules together, with more than one approver.
Built With
- arc
- circle
- claude
- express.js
- gemini-prediction-markets
- grok
- hardhat
- node.js
- openzeppelin
- quicknode-streams
- solidity
- typescript
- usdc
- viem
- x402