AutoGen (AG2) Integration
Add Lightning payment capability to AutoGen multi-agent conversations. Agents can access L402-protected APIs with automatic micropayments.
Install
pip install l402-requests[autogen]
Set your wallet:
export STRIKE_API_KEY="your-strike-api-key"
Quick Start
from autogen import AssistantAgent, UserProxyAgent
from l402_requests.integrations.autogen import register_l402_tools, configure_client
from l402_requests import L402Client, BudgetController
# Optional: configure budget
configure_client(L402Client(
budget=BudgetController(max_sats_per_request=500),
))
# Agents
assistant = AssistantAgent(
name="L402Assistant",
system_message=(
"You can access L402-protected APIs using l402_get and l402_post. "
"These tools automatically pay Lightning invoices when needed. "
"Check l402_spending_summary to monitor costs. "
"Reply TERMINATE when done."
),
llm_config={"model": "gpt-4o"},
)
user_proxy = UserProxyAgent(
name="UserProxy",
human_input_mode="NEVER",
is_termination_msg=lambda msg: "TERMINATE" in (msg.get("content") or ""),
code_execution_config=False,
)
# Register tools
register_l402_tools(caller=assistant, executor=user_proxy)
# Run
user_proxy.initiate_chat(
assistant,
message="Get the weather forecast for NYC from agent-commerce.store",
)
Functions
register_l402_tools(caller, executor)
Registers all three tools with an AutoGen caller/executor pair:
l402_get(url)— GET with automatic L402 paymentl402_post(url, body)— POST with automatic L402 paymentl402_spending_summary()— Session spending report
configure_client(client)
Set a custom L402Client before starting the conversation:
from l402_requests import L402Client, BudgetController
from l402_requests.integrations.autogen import configure_client
configure_client(L402Client(
budget=BudgetController(
max_sats_per_request=1000,
max_sats_per_hour=10000,
allowed_domains={"agent-commerce.store"},
),
))
Wallet Options
| Priority | Wallet | Environment Variable |
|---|---|---|
| 1 | LND | LND_REST_HOST + LND_MACAROON_HEX |
| 2 | NWC | NWC_CONNECTION_STRING |
| 3 | Strike | STRIKE_API_KEY |
| 4 | OpenNode | OPENNODE_API_KEY |