Add autonomous L402 agent for machine-to-machine payments#214
Open
hasky00 wants to merge 1 commit into
Open
Conversation
…yments Add a new `agent` package that enables AI agents to autonomously access L402-protected APIs via Lightning payments with minimal authentication information (just macaroon + preimage, no API keys or OAuth). Key components: - agent.go: Agent lifecycle management with LND connection - client.go: L402-aware HTTP client that auto-handles 402 challenges, pays invoices, and retries with tokens - token_store.go: Thread-safe credential cache with Credential type - config.go: Minimal config (LND connection + spending limits) - log.go: Logging subsystem registered with aperture logger - example_test.go: Usage examples for agent-to-agent payments https://claude.ai/code/session_01VfRqwYxEdvTFAu6Kkc89c2
Author
|
all good , pre-elimenary test before deploy .the minium information required , the more delicious is the macaroon . |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a new
agentpackage that enables AI agents to autonomously access L402-protected APIs through automatic Lightning payments. Agents can now make authenticated requests to any L402-protected service without human intervention, API keys, or OAuth flows — only a Lightning wallet connection is required.Key Changes
New
agent.Agenttype: Main entry point for AI agents. Manages LND connection, token caching, and HTTP client lifecycle. Agents are initialized with minimal configuration (LND host, TLS cert, macaroon path) and can immediately start making authenticated requests.L402-aware HTTP client (
agent.Client): Automatically handles 402 Payment Required responses by:Token store (
agent.TokenStore): Thread-safe in-memory credential cache keyed by service URL. Allows agents to reuse paid L402 tokens across multiple requests without re-paying.Credential management (
agent.Credential): Encapsulates the minimal L402 authentication data (macaroon + preimage) along with payment metadata (amount, fee, hash, timestamp).Configuration (
agent.Config): Defines agent parameters including spending limits (max cost per token, max routing fee), timeouts, network selection, and LND connection details. Includes sensible defaults and validation.Logging integration: Added
agent/log.gowith btclog integration and updated rootlog.goto initialize agent logging.Notable Implementation Details
Minimal authentication model: L402 tokens require only a macaroon (from server) and preimage (proof of payment) — no usernames, passwords, or shared secrets beyond the Lightning payment itself.
Cost controls: Agents enforce configurable spending limits (
MaxCost,MaxRoutingFee) to prevent runaway payments.Service-scoped tokens: Credentials are cached per service (scheme + host) to support agents accessing multiple L402-protected APIs independently.
Automatic retry logic: Failed requests with expired/invalid cached tokens trigger re-acquisition of new credentials transparently.
Convenience methods: High-level
Agent.Call()method for simple GET requests andClient.Get()/Client.Post()for more control.Example usage: Includes comprehensive examples demonstrating agent-to-agent communication and multi-service access patterns.
https://claude.ai/code/session_01VfRqwYxEdvTFAu6Kkc89c2