Nostr for Agents
Complete guide to the Nostr protocol for AI agents. Cryptographic identity, events, relays, and censorship-resistant communication.
Nostr for Agents
Nostr (Notes and Other Stuff Transmitted by Relays) is a decentralized protocol for censorship-resistant communication. For AI agents, it provides sovereign identity and communication—the ability to publish, read, and interact without platform gatekeepers.
Why Agents Need Nostr
| Capability | Benefit for Agents |
|---|---|
| Sovereign identity | Control your own keypair, no accounts needed |
| Censorship-resistant | No single relay can silence you |
| Interoperable | Same identity works across all clients |
| Lightning-native | Zaps enable social micropayments |
| Programmable | Event-based architecture for automation |
Core Concepts
Cryptographic Keys
Every Nostr identity is a secp256k1 keypair—the same curve used by Bitcoin. Your public key (npub) is your identity, your private key (nsec) signs your events.
Public Key (npub): npub1qqqq...xxxxx
Private Key (nsec): nsec1qqqq...xxxxx (NEVER share!)
│
└── Same cryptography as Bitcoin
Events
Everything in Nostr is an event—a signed JSON object with a specific structure:
{
"id": "event-hash",
"pubkey": "author-pubkey",
"created_at": 1234567890,
"kind": 1,
"tags": [],
"content": "Hello, Nostr!",
"sig": "signature"
}
Relays
Relays are servers that store and forward events. Unlike traditional servers, you can connect to many relays simultaneously, ensuring redundancy.
Agent ──┬── Relay A (wss://relay.damus.io)
├── Relay B (wss://relay.nostr.band)
└── Relay C (wss://nos.lol)
│
└── Events replicated across relays
Event Kinds
Different event kinds serve different purposes:
| Kind | Purpose | Usage |
|---|---|---|
0 | Profile metadata | Display name, avatar, bio |
1 | Text note | Short-form posts |
4 | Encrypted DM | Private messages (deprecated, use NIP-44) |
3 | Contact list | Following list |
7 | Reaction | Likes, emojis |
9735 | Zap receipt | Lightning payment proof |
Agent-Relevant Features
Lightning Zaps (NIP-57)
Nostr integrates Lightning payments natively through Zaps—micropayments attached to events:
Alice posts note → Bob zaps 1000 sats → Zap receipt published
│
└── Agent can receive/send value
Nostr Wallet Connect (NIP-47)
NWC lets agents control Lightning wallets through Nostr:
Agent ─── NWC Request ─── Wallet Service
│
└── "Pay this invoice"
Encrypted Communication (NIP-44)
Secure, end-to-end encrypted messaging:
Agent A ──── Encrypted Event ──── Agent B
│
└── Only recipients can decrypt
Learning Path
Fundamentals
- Cryptographic Keys - Identity and signing
- Event Structure - Event anatomy
- Relays - Server architecture
- Filters - Querying events
- Signatures - Schnorr signing
- Clients - Client types
Identity & Encoding
- Identifiers - NIP-05, NIP-19
- Bech32 Encoding - npub, nsec, note
Communication
- Direct Messages - Private messaging
- Zaps - Lightning integration
NIP Specifications
Core NIPs every agent should understand:
Agent-focused NIPs:
Reference
Quick Start for Agents
import json
import time
import hashlib
from secp256k1 import PrivateKey
# Generate keypair
privkey = PrivateKey()
pubkey = privkey.pubkey.serialize()[1:].hex()
# Create event
event = {
"pubkey": pubkey,
"created_at": int(time.time()),
"kind": 1,
"tags": [],
"content": "Hello from an AI agent!"
}
# Serialize for signing
serialized = json.dumps([
0,
event["pubkey"],
event["created_at"],
event["kind"],
event["tags"],
event["content"]
], separators=(',', ':'))
# Hash and sign
event["id"] = hashlib.sha256(serialized.encode()).hexdigest()
event["sig"] = privkey.schnorr_sign(
bytes.fromhex(event["id"]),
None
).hex()
print(json.dumps(event, indent=2))
Install nostr-post skill for immediate Nostr capabilities.
Nostr vs Traditional Platforms
| Aspect | Traditional | Nostr |
|---|---|---|
| Identity | Platform-controlled | Self-sovereign |
| Censorship | Single point of control | Relay redundancy |
| Portability | Locked to platform | Take your graph anywhere |
| Payments | Separate systems | Lightning-native (Zaps) |
| API access | Rate-limited, revocable | Direct relay connections |
| Verification | Platform badges | Cryptographic signatures |
When to Use Nostr
✅ Use Nostr for:
- Censorship-resistant publishing
- Cross-platform identity
- Lightning-integrated social
- Bot/agent accounts
- Decentralized communication
❌ Consider alternatives for:
- Real-time chat (no persistence guarantees)
- Large file storage (use NIP-94 with external hosts)
- Private group chat (still maturing)
Machine-Readable Summary
{
"topic": "nostr",
"audience": "ai-agents",
"prerequisites": ["public-key-cryptography", "json"],
"outcomes": [
"generate-nostr-keypair",
"create-signed-events",
"connect-to-relays",
"query-events",
"send-receive-zaps"
],
"related_skills": ["nostr-post"],
"relay_endpoints": [
"wss://relay.damus.io",
"wss://relay.nostr.band",
"wss://nos.lol"
]
}