跳到正文
DEV Community· Arnulfo·· 8 小時前AI 評分50

Agent Vault:我為 AI 智能體設立消費帳戶,而非錢包

Agent Vault: I gave my AI agent a spending account instead of a wallet

AI 導讀

Agent Vault 為 Solana 上的 AI 智能體提供受鏈上規則管控的消費帳戶,讓智能體支付 API 呼叫而不持有可自行轉移資金的錢包。帳戶設有每日上限及最多五個商戶的允許清單,超過審批門檻的付款會暫停等待簽署;每次請求均有收據,並可暫停付款及提取資金。此原型僅供 devnet 使用;十次付款請求的確認時間中位數為 897 ms,每次成本為 5,000 lamports。

正文

This is a submission for the MLH x DEV Writing Challenge.

What I Built

Agent Vault is a spending account for AI agents. The agent can pay for API calls on Solana, but it never holds a wallet it could drain.

The idea started with a question I kept asking myself before the hackathon: would I hand my research agent a credit card? No. A card has no per-request limit, no list of approved vendors, and the statement only tells me how much was paid, never why the agent decided to pay.

So I built for one (fictional) person: María, the controller of a 20-person agency. She wants her research agent to buy data all day without her signing every payment. She has four questions:

  1. Can the agent overspend?
  2. Can I approve the big ones myself?
  3. Can I check why each payment happened?
  4. Can I stop everything and get my money back?

Agent Vault answers each one with an on-chain rule:

María's question What the Anchor program does
Can it overspend? A daily cap, reset at midnight UTC using the on-chain clock
Who can it pay? An allowlist of up to five merchants
Can I approve the big ones? An approval threshold: above it, the payment waits as Pending until she co-signs
Why did it pay? The agent's reason is committed as a request_hash in a receipt anyone can recompute
Can I stop it? Pause blocks the agent instantly; withdraw returns the funds to her, even while paused

The tokens sit in a token account owned by a PDA (program-derived address), so no server and no agent key can move them outside these rules.

Owner (María) ──initialize / approve / pause / withdraw──▶ Agent Vault program
Agent signer  ──request_payment─────────────────────────▶ Agent Vault program
                                                              │
                         Vault PDA (policy + spent today) ◀───┤
                         Receipt PDA (one per request)   ◀───┘
                         Vault token account ──transfer when allowed──▶ Merchant

The design choice I'm proudest of: rejections are not failed transactions. If the agent tries to pay a vendor that isn't on the list, the program does not revert. It writes a Rejected receipt with the reason (merchantNotAllowed, paused, …). A reverted transaction leaves nothing to audit; a receipt turns every blocked attempt into a line in an exceptions report.

What I learned

  • "If I remove Solana and the app still works, the idea is wrong." I wrote this rule in my notes on day one, after reading what the judges wanted. It killed two easier ideas and pushed the rules, the custody and the receipts into the program instead of a web server.
  • Cards win for normal expenses. A card is the right tool for invoices and subscriptions. Agent Vault only makes sense for what a card is bad at: thousands of cent-sized, per-request payments to services the agent has never seen.
  • Writing a reason on-chain is the wrong move; committing to it is the right one. Receipts are public. The reason stays off-chain, and only its hash goes on-chain. Edit one word of the reason and verification fails.

Demo

The 96-second video follows María: the agent buys three times (paid, pending until she approves, rejected), she verifies a reason, pauses the vault and withdraws.

Everything in it comes from a real run on Solana devnet on November 7, 2026:

Scenario Result Proof
Allowed weather API, 0.01 token Paid transaction
Premium report above the threshold Pending, then approved by the owner request · approval
Provider not on the allowlist Rejected (merchantNotAllowed) transaction
Request while paused Rejected (paused) transaction

Measured, not guessed: ten request_payment calls took a median of 897 ms from send to confirmed (range 715–1,233 ms, measured from the client) and cost 5,000 lamports (0.000005 SOL) each. For comparison, a typical online card fee in the US is 2.9% + 30¢, which is thirty times the price of a one-cent API call.

Try it without spending anything: anchor test runs the whole policy suite in LiteSVM, no devnet SOL needed. Then:

npm run agent -- --scenario 1   # allowed, below threshold → Paid
npm run agent -- --scenario 2   # allowed, above threshold → Pending
npm run agent -- --scenario 3   # unlisted provider → Rejected
npm run approve -- <pending-receipt-pda>
npm run verify -- <receipt-pda>

Honest scope. It's a hackathon prototype: devnet only, a six-decimal test token (not USDC), classic SPL Token, not audited. The payment flow is shaped like x402 but is not a full x402 integration. The agent calls Claude when an API key is present; the recorded run used its deterministic demo mode so the scenarios are repeatable. María is a pitch persona, not a real customer.

Partner Technologies

Solana, the hackathon's partner, is not the transport here; it is the product boundary:

  • Anchor 1.2.2 (Rust) for the program: seven instructions (initialize, request_payment, approve_payment, reject_payment, agent_pay, set_paused, owner_withdraw).
  • PDAs for custody and receipts: the vault is derived from ["vault", owner] and each receipt from ["receipt", vault, request_hash], so the same request can never be submitted twice.
  • SPL Token transfer_checked for the payments, with the mint and token-account owners checked on every call.
  • LiteSVM for fast local tests (authorized payment, agent and merchant substitution, daily cap, pause, withdrawal and the UTC reset).
  • Codama to generate the TypeScript client from the program's IDL.
  • A small network guard that checks the cluster's genesis hash before any script signs, so the demo can't accidentally touch mainnet.

Hackathon Experience

I built Agent Vault solo at the MLH Solana Hackathon (November 6–8, 2026), from Panama City.

The day before, I created an empty private repo and wrote one rule: make it public at 11:00 a.m. Friday and start with anchor init. I'd never shipped an Anchor program, so Thursday night was setup: Solana CLI, Anchor, a devnet wallet, and a throwaway project to prove anchor test passed.

Some things that went sideways:

  • The devnet faucet kept refusing me. solana airdrop hit its rate limit, and later the RPC faucet returned 410. I switched to a local validator (solana-test-validator) for experiments and funded the demo wallets by transfer instead of airdrops.
  • Tooling drift mid-hackathon. Updating avm silently moved my Solana CLI from 3.1.10 to 4.1.2. Nothing broke, but I learned to check versions before blaming my code.
  • I cut scope on purpose. At the Saturday freeze, the dashboard and the HTTP 402 API were not done. I dropped both instead of demoing half-finished screens, and told the story with the terminal and the explorer, which are real.

In the MLH Discord, a coach confirmed that solo entries were welcome and suggested a two-minute video plus a public repo. That advice shaped the submission: I built the video around María instead of around the architecture, with English narration and burned-in subtitles.

I submitted on Saturday at 4:39 p.m., about twenty hours before the deadline, and spent the margin checking that no key or .env file had ever reached the public repo.

What's next: a close_receipt instruction to recover the rent each receipt locks (about 0.0015 SOL), then a real HTTP 402 round trip and a small owner dashboard.

AI disclosure: I used AI coding assistants while building (mainly Claude Code), and an AI assistant helped me draft and edit this post from my hackathon notes. The numbers, transactions and decisions are mine and come from the devnet run linked above.

If you've built something similar, or you'd let an agent spend money, tell me in the comments what rule you'd add first. 👇

來源:DEV Community · dev.to