Franklin icon indicating copy to clipboard operation
Franklin copied to clipboard

feat(market): /market command + agent_talent tool to hire marketplace skills

Open Zambala108 opened this issue 5 months ago • 0 comments

What

A buyer surface for the BlockRun agent marketplace (business.blockrun.ai) — a catalog of paid AI skills published by other creators, each runnable for ONE standard single-leg exact x402 USDC payment on Base. Two surfaces over one shared payment path (src/market/client.ts):

Surface For Actions
/market command a human at the terminal /market (browse top), /market <keyword> (search), /market info <slug> (detail card), /market run <slug> <input> (hire)
agent_talent tool the agent, autonomously mid-task {action:"list", query?} (free discovery), {action:"run", slug, input} (hire, paid)

Browsing/search/info are free GETs against the public catalog; run answers a 402 with one wallet-signed payment.

Why

The marketplace speaks standard x402, so Franklin pays it with the same EVM wallet and the same @blockrun/llm signer it already uses for the gateway. The only deltas from the existing BlockRun gateway primitive (src/tools/blockrun.ts) are the x-payment header name and the base URL (BLOCKRUN_MARKET_URL, default https://business.blockrun.ai). This makes Franklin a first-class buyer of marketplace talent — the agent can hire a specialized skill (live data, a domain analysis) for a sub-task it can't do well itself, charged only on success.

Note on naming: Franklin's skillRegistry already owns the word "skill" (local SKILL.md slash commands), so the marketplace gets its own namespace (/market, agent_talent) to avoid collision.

How it pays

src/market/client.ts is the single payment path shared by both surfaces:

  1. POST /api/v1/skills/<slug>/run → 402 with the standard challenge body { accepts:[{amount, payTo, network, …}] }.
  2. extractPaymentDetails + createPaymentPayload (@blockrun/llm) sign one EIP-3009 exact authorization for exactly the advertised amount.
  3. Retry with the x-payment header → result. Fails closed (the route settles only on success, so any non-2xx = no charge).

Receipts

Regression test (test/market.local.mjs, in npm test) drives the built client against a mock marketplace and asserts Franklin signs the EXACT advertised price — the invariant the live route enforces with signedValueMicro === totalMicro — plus the discovery parse, keyword filter, and fail-closed-no-charge path. It caught a real bug: a Run — <skill> payment description with an em-dash made @blockrun/llm's btoa-based payload encoding throw Invalid character on any non-Latin1 skill name; the description is now ASCII-stripped before signing.

Live E2E vs. real Coinbase CDP (Base mainnet). Franklin's built dist client (both runMarketSkill and the agent_talent tool) ran against a shim wired to business.blockrun.ai's real verifyPayment + real CDP /verify:

[shim] 402 challenge issued (network: eip155:8453 price: 0.01)
[shim] verifyPayment: {"valid":true,"payer":"0x1f44…"}
[shim] signedValueMicro: 10000 expected: 10000
[shim] PASS — payer 0x1f44…
Franklin runMarketSkill: ok:true status:200 paidUsd:0.01

This closes the one untested real-world link: CDP accepts the signature @blockrun/llm produces, and it clears the route's strict exact-price gate. The remaining legs (on-chain settle + instant creator payout) are proven on Base mainnet in the business repo: settle 0x1cea9dcdd2eff4e4474f1d504acf217d7c6ac85bca27432ce3dc476a6565e4da, payout 0xc0d971c3501cf4624e5c2601ec4bc77f0d2380e76fc0ee5091dcd61f8f18a066.

Tests / gates

  • npx tsc --noEmit ✓ · npm run build ✓ · node dist/index.js --help ✓
  • npm test → 453/453 pass (incl. the new 5 market tests and the English-only source gate)

Notes

  • Base-only by design: a hire always pays from the EVM wallet regardless of the session chain.
  • No new deps. agent_talent is registered in allCapabilities; /market is registered in /help and command discovery.

🤖 Generated with Claude Code

Zambala108 avatar Jun 13 '26 07:06 Zambala108