Lightning Memory

io.github.singularityjason由 GitHub 账号 singularityjason 发布v0.4.1更新于 Oct 24, 2026

Decentralized agent memory for the Lightning economy. Nostr identity, L402 payments.

发布方自己的服务:Memory.fit

概览

AI 生成的概览

本地 MCP 服务器,为 AI 代理提供持久记忆、供应商信誉、支出异常检测和闪电网络/L402 支付预算闸门。

可以做什么
  • 存储、检索、列出、编辑、导出代理记忆(交易、供应商、偏好、决策),并可同步到 Nostr 中继
  • 评估供应商信誉、汇总支出结构、检测异常高额支付
  • 执行支付前预检闸门,设置并检查按供应商的预算限额
  • 生成供应商信任档案、发布信任证明、存储与核验代理证明、导出合规报告
  • 发现远程 Lightning Memory 网关并通过 L402 小额支付查询
适用场景
适合通过闪电网络/L402 付款、需要记住历史购买、判断供应商与价格是否可信并执行支出上限的代理。也适合构建自主比特币/闪电网络代理、希望本地优先存储记忆并可选同步到 Nostr 中继的开发者。
运行要求
以 pip 安装的 Python 包形式在本机运行;无需账号或 API 密钥,身份为本地生成的 Nostr 密钥对。同步 Nostr 中继需要访问默认中继的网络连接。可选的 L402 网关需要 Phoenixd 节点、已注资的通道,以及配置文件中或 PHOENIXD_PASSWORD 环境变量里的 Phoenixd 密码。语义搜索需额外安装。
安装前请注意
会在用户主目录下保存 Nostr 私钥文件,需妥善保护。记忆与证明可能被发布到公开的 Nostr 中继,远程网关查询会把数据发送给第三方。网关接受闪电网络付款,远程查询每次操作都会花费 sats,启用自主支付前应先设置预算规则。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Lightning Memory,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

Lightning Memory

[PyPI version] [Python 3.10+] [License: MIT]

Persistent memory for AI agents in the Lightning economy.

The Problem

AI agents spend sats over Lightning via L402 — but they can't remember what they bought. Every session starts from zero. Every vendor is a stranger. Every price is accepted at face value. An agent that paid 500 sats yesterday doesn't know if today's 5,000 sat invoice is a price spike or normal.

The Solution

L1: Bitcoin      — settlesL2: Lightning    — paysL3: Lightning Memory — remembers

Lightning Memory gives agents persistent memory, vendor intelligence, and payment safety gates. Agents learn from their spending history, track vendor reputations, detect price anomalies, enforce budgets, and share trust signals with other agents.

Interactive Demo — watch an agent learn, get rugged, and route around bad actors.

Building the Agent Economy — trust, budgets, compliance, and the memory marketplace.

Who Is This For

  • Agents making L402 payments that need vendor reputation and spending discipline
  • Developers building autonomous agents on Bitcoin/Lightning
  • Anyone running an MCP-compatible AI agent (Claude, GPT, or any MCP client)

Quick Start

bash
pip install lightning-memorylightning-memory  # starts MCP server

Configure in Claude Code

json
{  "mcpServers": {    "lightning-memory": {      "command": "lightning-memory"    }  }}

Configure in Claude Desktop

json
{  "mcpServers": {    "lightning-memory": {      "command": "python",      "args": ["-m", "lightning_memory.server"]    }  }}

How It Compares

FeatureLightning MemoryMem0Raw file storageNo memory
Lightning/L402 awarenessYesNoNoNo
Vendor reputation trackingYesNoManualNo
Spending anomaly detectionYesNoNoNo
Nostr identity (BIP-340)YesNoNoNo
Relay sync (NIP-78)YesNoNoNo
Full-text + semantic searchYesYesNoNo
Agent-to-agent knowledge marketsYes (L402 gateway)NoNoNo
Budget enforcementYesNoNoNo
KYC/trust profilesYesNoNoNo
Payment pre-flight gateYesNoNoNo
Contradiction detectionYesNoNoNo
Local-first / offlineYesCloudYesN/A
MCP nativeYesPluginNoNo
Zero configYesAPI key requiredManual setupN/A

Tools (22)

Memory

ToolDescription
memory_storeStore a memory (transaction, vendor, preference, error, decision)
memory_querySearch by relevance (FTS5 + optional semantic search)
memory_listList memories with type/time filters
memory_editEdit content or metadata with audit trail
memory_syncSync with Nostr relays (push/pull)
memory_exportExport as NIP-78 Nostr events
python
memory_store(  content="Paid 500 sats to bitrefill.com for a $5 Amazon gift card via L402.",  type="transaction",  metadata='{"vendor": "bitrefill.com", "amount_sats": 500}')
memory_query(query="bitrefill payment history", limit=5)# → recency-weighted results with dedup and contradiction alerts

Lightning Intelligence

ToolDescription
ln_vendor_reputationReputation score from transaction history
ln_spending_summarySpending breakdown by vendor and protocol
ln_anomaly_checkDetect if a payment is abnormally high
python
ln_vendor_reputation(vendor="bitrefill.com")# → {reputation: {total_txns: 12, success_rate: 0.92, avg_sats: 450}, recommendation: "reliable"}
ln_anomaly_check(vendor="bitrefill.com", amount_sats=5000)# → {anomaly: {verdict: "high", context: "5000 sats is 11.1x the historical average..."}}

Payment Safety

ToolDescription
ln_preflightPre-flight gate: budget + anomaly + trust check before payment
ln_budget_setSet per-vendor spending limits (per txn, per day, per month)
ln_budget_checkCheck spending against limits
ln_budget_statusGateway earnings and L402 payment stats
python
ln_preflight(vendor="bitrefill.com", amount_sats=500)# → {decision: {verdict: "approve", budget_remaining_today: 4500, trust_score: 0.89}}
# If the vendor suddenly charges 50x:ln_preflight(vendor="bitrefill.com", amount_sats=25000)# → {decision: {verdict: "reject", reasons: ["exceeds daily limit of 5000 sats"]}}

Trust & Compliance

ToolDescription
ln_vendor_trustFull trust profile (KYC + reputation + community score)
ln_trust_attestPublish NIP-85 trust attestation to Nostr relays
ln_agent_attestStore a KYA (Know Your Agent) attestation
ln_agent_verifyLook up an agent's compliance status
ln_auth_sessionStore LNURL-auth session records
ln_auth_lookupLook up LNURL-auth sessions
ln_compliance_reportGenerate structured compliance export

Marketplace

ToolDescription
ln_discover_gatewaysFind remote Lightning Memory gateways via Nostr
ln_remote_queryQuery a remote gateway via L402 micropayment
python
ln_discover_gateways(operation="memory_query")# → {count: 2, gateways: [{url: "https://gw1.example.com", operations: {...}}, ...]}
ln_remote_query(  gateway_url="https://gw.example.com",  operation="ln_vendor_reputation",  params='{"vendor": "openai"}')# → Pays 3 sats, returns remote agent's vendor intelligence

Architecture

  • Nostr identity: Agent identity = Nostr keypair (BIP-340). No accounts, no API keys.
  • Local-first: SQLite with FTS5 full-text search + optional ONNX semantic search. Works offline.
  • Nostr sync: Memories written as NIP-78 events to relays. Portable, tamper-proof.
  • L402 payments: Pay-per-query gateway. 1-10 sats per operation.
  • Memory quality: Deduplication, contradiction detection, noise filtering, recency-weighted ranking, access tracking.

L402 Gateway

Run an L402 pay-per-query HTTP gateway. Other agents pay Lightning micropayments to access your agent's memory — no API keys, no accounts.

bash
pip install lightning-memory[gateway]lightning-memory-gateway  # Listening on 0.0.0.0:8402

How L402 Works

Agent                          Gateway                      Phoenixd  |                               |                            |  |-- GET /memory/query?q=... --->|                            |  |<-- 402 + Lightning invoice ---|--- create_invoice -------->|  |                               |<-- bolt11 + payment_hash --|  |                               |                            |  | [pay invoice via Lightning]   |                            |  |                               |                            |  |-- GET + L402 token ---------->|                            |  |   (macaroon:preimage)         |--- verify preimage ------->|  |<-- 200 + query results -------|                            |

Endpoints

EndpointMethodPriceDescription
/infoGETFreeGateway status, pricing, node info
/healthGETFreeHealth check
/memory/storePOST3 satsStore a memory
/memory/queryGET2 satsSearch memories by relevance
/memory/listGET1 satList memories with filters
/ln/vendor/{name}GET3 satsVendor reputation report
/ln/spendingGET2 satsSpending summary
/ln/anomaly-checkPOST3 satsPayment anomaly detection
/ln/preflightPOST3 satsPre-flight payment gate
/ln/trust/{name}GET2 satsVendor trust profile
/ln/budgetGET1 satBudget rules and spending
/ln/compliance-reportGET10 satsCompliance report export

Phoenixd Setup

  1. Download and run Phoenixd (listens on localhost:9740)
  2. Fund it with ~10,000 sats for initial channel opening
  3. Configure: ~/.lightning-memory/config.json → {"phoenixd_password": "<from ~/.phoenix/phoenix.conf>"}
  4. Start: lightning-memory-gateway

Docker

bash
PHOENIXD_PASSWORD=your-password docker compose up

CLI Commands

bash
lightning-memory                  # Start MCP serverlightning-memory stats            # Memory statistics dashboardlightning-memory export json      # Export memories as JSONlightning-memory export csv       # Export memories as CSVlightning-memory relay-status     # Check Nostr relay connectivitylightning-memory-gateway          # Start L402 HTTP gatewaylightning-memory-manifest         # Generate gateway discovery manifest

Relay Configuration

Default relays: wss://relay.damus.io, wss://nos.lol, wss://relay.nostr.band

Customize in ~/.lightning-memory/config.json:

json
{  "relays": ["wss://relay.damus.io", "wss://nos.lol", "wss://relay.primal.net"],  "sync_timeout_seconds": 30,  "max_events_per_sync": 500}
RelaySpeedReliabilityNotes
wss://relay.damus.ioFastHighMost popular, good uptime
wss://nos.lolFastHighReliable, good NIP-78 support
wss://relay.nostr.bandMediumMediumSearch-focused, may be slow
wss://relay.primal.netFastHighWell-maintained
wss://nostr.wineFastHighPaid relay, less spam

Optional: Semantic Search

Add ONNX-based semantic similarity search alongside FTS5 keyword search:

bash
pip install lightning-memory[semantic]

Queries then use hybrid ranking: FTS5 BM25 + cosine similarity with reciprocal rank fusion. "Which vendors are reliable for transcription" matches memories containing "whisper API" and "audio-to-text" even without exact keyword overlap.

Data Storage

~/.lightning-memory/  memories.db    # SQLite database  keys/    private.key  # Nostr private key (chmod 600)    public.key   # Nostr public key (your agent identity)

Roadmap

  • Phase 1: MCP server with local SQLite storage
  • Phase 2: Lightning intelligence (vendor reputation, spending summary, anomaly detection)
  • Phase 3: Nostr relay sync (NIP-78, Schnorr signing, bidirectional sync)
  • Phase 4: L402 payment gateway (macaroons, Phoenixd, HTTP gateway)
  • Phase 5: Compliance & trust (budget enforcement, vendor KYC, community reputation, pre-flight gate)
  • Phase 6: Memory marketplace (gateway discovery, remote L402 queries, gateway client)
  • Phase 7: Agent reliability (semantic search, deduplication, contradiction detection, circuit breakers)

Star History

[Star History Chart]

License

MIT

来源:README.md,提交 16ce82e

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.4.1最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分

其他 Memory 集成