|
| 1 | +# le-agent-sdk |
| 2 | + |
| 3 | +[](https://pypi.org/project/le-agent-sdk/) |
| 4 | +[](https://github.com/ArcadeLabsInc/lightning-enable-agent-sdk-python/actions/workflows/test.yml) |
| 5 | +[](https://pypi.org/project/le-agent-sdk/) |
| 6 | +[](https://opensource.org/licenses/MIT) |
| 7 | + |
| 8 | +Python SDK for Lightning Enable Agent Service Agreements. |
| 9 | + |
| 10 | +Discover, negotiate, and settle agent-to-agent services over Nostr with L402 Lightning payments. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +```bash |
| 15 | +pip install le-agent-sdk |
| 16 | +``` |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +### Provider: Publish a Service |
| 21 | + |
| 22 | +Register an agent capability on the Nostr network so other agents can discover it. |
| 23 | + |
| 24 | +```python |
| 25 | +import asyncio |
| 26 | +from le_agent_sdk import AgentManager, AgentCapability, AgentPricing |
| 27 | + |
| 28 | +async def main(): |
| 29 | + manager = AgentManager( |
| 30 | + private_key="<your_hex_private_key>", |
| 31 | + relay_urls=["wss://agents.lightningenable.com"], |
| 32 | + ) |
| 33 | + |
| 34 | + cap = AgentCapability( |
| 35 | + service_id="translate-v1", |
| 36 | + categories=["ai", "translation"], |
| 37 | + content="AI translation service. Supports 50+ languages.", |
| 38 | + pricing=[ |
| 39 | + AgentPricing(amount=10, unit="sats", model="per-request"), |
| 40 | + ], |
| 41 | + l402_endpoint="https://api.lightningenable.com/l402/proxy/translate", |
| 42 | + hashtags=["translation", "ai"], |
| 43 | + ) |
| 44 | + |
| 45 | + event_id = await manager.publish_capability(cap) |
| 46 | + print(f"Published capability: {event_id}") |
| 47 | + |
| 48 | + # Listen for incoming service requests |
| 49 | + async for request in manager.listen_requests(): |
| 50 | + print(f"Request from {request.pubkey}: {request.content}") |
| 51 | + |
| 52 | +asyncio.run(main()) |
| 53 | +``` |
| 54 | + |
| 55 | +### Requester: Discover and Use Services |
| 56 | + |
| 57 | +Find available services and settle via L402 payments. |
| 58 | + |
| 59 | +```python |
| 60 | +import asyncio |
| 61 | +from le_agent_sdk import AgentManager |
| 62 | + |
| 63 | +async def main(): |
| 64 | + manager = AgentManager( |
| 65 | + private_key="<your_hex_private_key>", |
| 66 | + relay_urls=["wss://agents.lightningenable.com"], |
| 67 | + ) |
| 68 | + |
| 69 | + # Discover translation services |
| 70 | + capabilities = await manager.discover( |
| 71 | + categories=["translation"], |
| 72 | + hashtags=["ai"], |
| 73 | + limit=10, |
| 74 | + ) |
| 75 | + |
| 76 | + for cap in capabilities: |
| 77 | + print(f"[{cap.service_id}] {cap.content[:60]}...") |
| 78 | + if cap.pricing: |
| 79 | + print(f" Price: {cap.pricing[0].amount} {cap.pricing[0].unit}/{cap.pricing[0].model}") |
| 80 | + |
| 81 | + # Settle via L402 if endpoint available |
| 82 | + chosen = capabilities[0] |
| 83 | + if chosen.l402_endpoint: |
| 84 | + result = await manager.settle_via_l402(chosen) |
| 85 | + print(f"Result: HTTP {result.status_code}") |
| 86 | + |
| 87 | +asyncio.run(main()) |
| 88 | +``` |
| 89 | + |
| 90 | +## API Reference |
| 91 | + |
| 92 | +### Core Classes |
| 93 | + |
| 94 | +| Class | Description | |
| 95 | +|-------|-------------| |
| 96 | +| `AgentManager` | Main entry point. Manages Nostr connections, publishes capabilities, discovers services, and handles L402 settlement. | |
| 97 | +| `AgentCapability` | Defines a service offering with pricing, categories, endpoints, and metadata. Published as Nostr kind 38400 events. | |
| 98 | +| `AgentServiceRequest` | Represents a request for service from one agent to another (kind 38401). | |
| 99 | +| `AgentServiceAgreement` | Bilateral contract between provider and requester (kind 38402). | |
| 100 | + |
| 101 | +### Nostr Layer |
| 102 | + |
| 103 | +| Class | Description | |
| 104 | +|-------|-------------| |
| 105 | +| `RelayClient` | WebSocket client for Nostr relay communication. Handles subscriptions and event publishing. | |
| 106 | +| `NostrEvent` | Nostr event construction, serialization, and signing. | |
| 107 | +| `TagParser` | Utilities for parsing and building Nostr event tags. | |
| 108 | + |
| 109 | +### Payment Layer |
| 110 | + |
| 111 | +| Class | Description | |
| 112 | +|-------|-------------| |
| 113 | +| `L402Client` | HTTP client with automatic L402 challenge-response handling. Wraps [l402-requests](https://github.com/ArcadeLabsInc/l402-requests). | |
| 114 | +| `AgentPricing` | Pricing model (amount, unit, per-request/per-token). | |
| 115 | + |
| 116 | +## Protocol |
| 117 | + |
| 118 | +Agent Service Agreements use three Nostr event kinds: |
| 119 | + |
| 120 | +- **38400** -- Agent Capability: provider advertises available services |
| 121 | +- **38401** -- Agent Service Request: requester asks for a service |
| 122 | +- **38402** -- Agent Service Agreement: bilateral contract with terms and pricing |
| 123 | + |
| 124 | +Settlement happens via L402 (Lightning HTTP 402) through Lightning Enable endpoints. |
| 125 | + |
| 126 | +## Related Projects |
| 127 | + |
| 128 | +- [l402-requests](https://github.com/ArcadeLabsInc/l402-requests) -- Python L402 HTTP client |
| 129 | +- [Lightning Enable](https://lightningenable.com) -- L402 infrastructure and agent payment rails |
| 130 | +- [NostrWolfe](https://github.com/ArcadeLabsInc/nostrwolfe-ios) -- Nostr client with native L402 support |
| 131 | + |
| 132 | +## License |
| 133 | + |
| 134 | +MIT |
0 commit comments