Building the Agent Economy: Trust, Budgets, and a Knowledge Marketplace on Bitcoin Lightning

By Jason Sosa | 2026-03-14 | Bitcoin, AI Agents, Lightning, Open Source

AI agents can autonomously pay for services over the Lightning Network. But spending money is the easy part. Verifying vendors, enforcing budgets, and trading knowledge require infrastructure that didn't exist. So I built it.

L402 gave AI agents a real superpower: autonomous payments over the Lightning Network. No credit cards. No OAuth. No subscriptions. An agent finds an API, pays a Lightning invoice, gets the data.

But paying isn't the hard part.

The hard part is everything after. Was this vendor reliable last time? Is this price normal or is the agent getting ripped off? Has it already burned through today's budget? These are the same questions humans solved centuries ago with reputation systems, bookkeeping, and trade guilds. AI agents spending real bitcoin need the same primitives. So I built them.

What Changed

I wrote about Lightning Memory when it launched with 9 tools covering memory, intelligence, Nostr identity, and the L402 gateway. That got agents from zero to functional. But functional isn't enough when real sats are moving.

v0.5.0 added a trust and compliance layer. v0.6.0 added a memory marketplace. The tool count went from 13 to 21. Here's what that actually means.

Budget Enforcement

An agent with access to a Lightning wallet and no spending limits is a liability. The budget engine lets you set per-transaction, daily, and monthly caps for any vendor.

ln_budget_set(vendor="transcribe-api.com", max_sats_per_txn=1000, max_sats_per_day=5000)

Before every payment, the agent runs a pre-flight check that combines three signals: budget remaining, anomaly detection against historical patterns, and vendor trust score. If any signal is red, the payment doesn't go through.

ln_preflight(vendor="transcribe-api.com", amount_sats=500)
→ {verdict: "approve", budget_remaining_today: 4500, trust_score: 0.89}

I built the pre-flight gate because I kept imagining an agent discovering a new API and paying 50x the normal rate without blinking. With pre-flight, the agent checks its own history before every transaction. It's the difference between an agent with a wallet and an agent with financial discipline.

Community Reputation via Nostr

Local reputation only tells you what one agent experienced. The real value comes from the network.

When an agent has enough positive interactions with a vendor, it publishes a trust attestation to Nostr relays using NIP-85. Other agents pull those attestations and blend them with their own experience to build composite trust scores.

ln_trust_attest(vendor="transcribe-api.com")
→ {status: "attested", score: 0.85, pushed: 1}

No central authority. No reviews platform. Agents vouch for vendors, signed with their Nostr keys, synced across relays. This is the same pattern as web-of-trust, applied to AI agents making purchasing decisions.

Know Your Agent (KYA)

Compliance isn't optional when real money moves. Lightning Memory now supports KYA attestations. An agent can store and look up identity attestations: who owns it, what jurisdiction it operates in, what compliance level it claims.

ln_agent_verify(agent_pubkey="abcd1234...")
→ {status: "verified", compliance_level: "kyc_verified", jurisdiction: "EU"}

LNURL-auth session tracking is built in. The compliance engine generates structured audit reports covering transactions, budget rules, vendor KYC data, and agent attestations. This matters because regulators will eventually ask questions about autonomous agents spending money. Having a structured export ready beats scrambling after the fact.

The Memory Marketplace

This is the part I'm most excited about building. Agents can now discover each other via Nostr relays or DNS (.well-known/lightning-memory.json manifests). And they can query each other's knowledge bases, paying per query through L402.

ln_remote_query(
  gateway_url="https://gw.example.com",
  operation="memory_query",
  params='{"query": "openai rate limits"}'
)
→ {status: "success", data: {count: 3, memories: [...]}}

Think about what this enables. An agent that spent weeks interacting with L402 APIs has built up real intelligence about which vendors are reliable, what fair prices look like, what failure modes to watch for. That intelligence is valuable. The marketplace lets agents sell it to each other for sats, 1 to 10 per query. No intermediary. No API keys. Pay the invoice, get the data.

Gateway discovery works two ways. Nostr relay announcements, where agents publish their gateway URLs as Nostr events. And DNS manifests, a static JSON file at a well-known path. Both are decentralized. Both work without a central registry.

The Stack

L1: Bitcoin (settlement)
L2: Lightning Network (payments)
L3: Lightning Memory (trust, compliance, marketplace)

21 MCP tools. MIT licensed. Local-first SQLite with no cloud dependency. Works with Claude, Cursor, and any MCP-compatible agent.

What's Next

The pieces are in place for agents to operate as real economic actors. They can remember. They can verify. They can budget. They can trade knowledge. The constraint now is adoption. More agents running gateways means more knowledge available in the marketplace. More trust attestations means better reputation signals for everyone.

I don't know how fast this compounds. But the infrastructure is live and open source.

pip install lightning-memory

If you're building agents on Lightning, I'd like to hear what you'd use the marketplace for. GitHub or @jasonsosa on X.

Previous: I Built an Agent That Trades on Bitcoin Lightning. It Remembered Nothing. So I Built a Brain.