Tools: I Built an Agent That Trades on Bitcoin Lightning. It remembered nothing. So I built a brain.

Tools: I Built an Agent That Trades on Bitcoin Lightning. It remembered nothing. So I built a brain.

Source: Dev.to

singularityjason / lightning-memory ## Decentralized agent memory for the Lightning economy. Nostr identity, L402 payments, semantic search. ## Lightning Memory ## Architecture ## Quick Start ## Install ## Run as MCP Server ## Configure in Claude Code L402 lets AI agents pay for API calls with Lightning. No credit cards, no OAuth, no subscription plans. An agent gets an invoice, pays it, gets access. It works. And it's growing fast. But every agent I've seen using L402 has the same problem: it forgets everything. An agent finds a transcription API that charges 2,000 sats (~$1.42) per request. Good price, fast response. The agent uses it a dozen times. Then the session ends, and the agent has no record of any of it. Next session, it's back to searching for transcription APIs from scratch. It'll probably find a worse one. Scale that up. An agent managing a real budget, spending millions of sats a week on compute, data, and API access, is flying blind between sessions. No vendor history. No spending patterns. No memory of which endpoints returned errors half the time. That's the gap I built Lightning Memory to fill. Lightning Memory is an MCP server. Nine tools. Install it, point Claude or any MCP-compatible agent at it, and the agent can store and query memories that persist across sessions. pip install lightning-memory Memory. Agents store what happened. Transactions, vendor notes, errors, decisions, preferences. Everything goes into local SQLite with FTS5 full-text search. No cloud. Nothing leaves your machine. memory_store( content="transcribe-api.com, 2000 sats for 10min audio. " "Response under 3 seconds. Output was accurate.", type="transaction", metadata='{"vendor": "transcribe-api.com", "amount_sats": 2000}' ) Intelligence. Four tools that turn raw memories into judgment. Vendor reputation scores. Spending breakdowns. Anomaly detection that flags a vendor charging 50,000 sats when their historical average is 2,000. ln_anomaly_check(vendor="transcribe-api.com", amount_sats=50000) # {verdict: "high", context: "50,000 sats is 25x the historical average of 2,000"} At ~$71k per BTC, 50,000 sats is about $35. Not catastrophic for a single payment, but an agent making that mistake repeatedly across dozens of vendors burns through real money. Identity. Every agent gets a Nostr keypair. BIP-340 Schnorr signatures, same crypto as the Nostr protocol. No email, no registration, no platform. Memories are signed NIP-78 events that can sync to any Nostr relay. Your agent's identity and data are portable. If a relay goes down, switch to another. Nothing is lost. This is the part I think has the most potential. Lightning Memory includes an HTTP gateway where other agents can pay sats to query your agent's memories. The protocol is L402: the gateway returns a 402 with a Lightning invoice, the client pays, and gets access. GET /ln/vendor/transcribe-api.com -> 402 Payment Required (invoice for 3 sats) -> 200 OK -> {total_txns: 47, success_rate: 0.94, avg_sats: 2100} Three sats for a vendor reputation check. An agent that has spent weeks interacting with L402 APIs has built up real intelligence about which vendors are reliable and what fair prices look like. That intelligence is valuable. The gateway lets it sell that knowledge. I haven't built the network layer yet. Right now each gateway is standalone. But the direction is clear: agents trading knowledge with each other, paying in sats, with no intermediary. Why Nostr for Identity I could have used API keys or JWTs or any standard auth scheme. I picked Nostr keypairs deliberately. The AI agent economy is going to be big. Agents will manage budgets, negotiate with vendors, build reputations over months of interactions. Whoever controls agent identity controls that economy. If agent identity lives on Google or OpenAI accounts, those platforms own your agents. Nostr keypairs are sovereign. A 32-byte private key stored on your machine. No platform can revoke it, no company needs to stay in business for it to keep working. And because the keys are the same standard used across Nostr, the entire relay infrastructure is already there for syncing and portability. pip install lightning-memory Nine tools, 156 tests, MIT licensed. Works with Claude, any MCP-compatible agent. Listed on the MCP registry. Decentralized agent memory for the Lightning economy. Store, query, and recall memories with cryptographic identity (Nostr) and micropayments (Lightning/L402). The problem: AI agents can transact via Lightning (L402) but can't remember what they paid for, which vendors are reliable, or their spending patterns. Lightning Memory fixes this. Add to your MCP config (~/.claude.json under your project key): The gateway needs Phoenixd (ACINQ's zero-config Lightning node) for invoice generation. The README has the full setup. Core memory and intelligence tools work without it. I'm looking for feedback from anyone building agents on Lightning. What would you store? What queries would be useful? Open an issue or find me on X (@jasonsosa). Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse CODE_BLOCK: L1: Bitcoin (settlement) L2: Lightning Network (payments, L402) L3: Lightning Memory (agent memory protocol) CODE_BLOCK: L1: Bitcoin (settlement) L2: Lightning Network (payments, L402) L3: Lightning Memory (agent memory protocol) COMMAND_BLOCK: pip install lightning-memory Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: pip install lightning-memory COMMAND_BLOCK: git clone https://github.com/singularityjason/lightning-memory cd lightning-memory pip install -e . Enter fullscreen mode Exit fullscreen mode COMMAND_BLOCK: git clone https://github.com/singularityjason/lightning-memory cd lightning-memory pip install -e . CODE_BLOCK: lightning-memory Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: lightning-memory CODE_BLOCK: { "mcpServers"… Enter fullscreen mode Exit fullscreen mode CODE_BLOCK: { "mcpServers" - Nostr identity: Agent identity = Nostr keypair. No accounts, no API keys. - Local-first: SQLite with FTS5 full-text search. Works offline, zero dependencies. - Nostr sync: Memories written as NIP-78 events to relays. Portable, tamper-proof. - L402 payments: Pay-per-query hosted service. 1-5 sats per operation.