Overview
TheRelayAgent class enables AI agents to:
- Discover services with reputation-based filtering
- Execute paid operations with automatic x402 payment
- Build workflows with fallbacks and retries
- Track outcomes for learning and optimization
Installation
Quick Start
Core Methods
constructor(config: AgentConfig)
Initialize the agent with wallet and configuration.
Parameters:
discoverServices(criteria: ServiceCriteria): Promise<SelectedService[]>
Find services matching criteria with reputation-based scoring.
Parameters:
execute<T>(serviceId: string, input: unknown): Promise<ExecutionResult<T>>
Execute a service with automatic x402 payment handling.
Parameters:
serviceId: Service identifier fromdiscoverServicesinput: Service-specific input data
- Agent calls service endpoint
- If 402 response: generate EIP-3009 signature
- Settle payment via Facilitator
- Retry request with payment ID
- Return service response
executeWorkflow<T>(steps: WorkflowStep[]): Promise<WorkflowResult<T>>
Execute multi-step workflow with fallbacks and retries.
Parameters:
getMemory(): AgentMemory
Access execution history and statistics for learning.
Returns:
Error Handling
Error Codes
Error Structure
Handling Errors
Advanced Usage
Custom Trust Policy
Workflow with Conditional Logic
Memory-Based Service Selection
Best Practices
1. Always Handle Errors
2. Use Workflows for Complex Operations
3. Track Outcomes for Learning
4. Use Trust Policies
Next Steps
Service SDK
Build and monetize services
Session Management
Use session budgets for efficiency
Error Handling
Robust error handling patterns
First Payment Guide
Complete tutorial with code