LangChain Agent Example¶
Example LangChain agent with autonomous X402 payment capabilities.
Setup¶
-
Install dependencies:
-
Set OpenAI API key:
-
Create and fund wallet:
-
Start the FastAPI server (in another terminal):
-
Run the agent examples:
What it does¶
The examples demonstrate three scenarios:
Example 1: Simple Agent¶
Creates an agent using the convenience function that can autonomously detect and pay for 402 responses.
Example 2: Custom Tools¶
Shows how to combine X402 payment capabilities with other LangChain tools.
Example 3: Multi-API¶
Demonstrates an agent making multiple payments to different APIs in a single workflow.
Key Features¶
- Autonomous Payments: Agent detects 402 responses and pays automatically
- Safety Limits:
max_paymentparameter prevents overspending - Transparent: Verbose mode shows payment decisions
- Flexible: Works with any X402-enabled API