Skip to main content

Overview

The RelayAgent 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
Design Philosophy: Decision abstraction, not CRUD. Agents focus on what to do, not how to do it.

Installation


Quick Start


Core Methods

constructor(config: AgentConfig)

Initialize the agent with wallet and configuration. Parameters:
Example:

discoverServices(criteria: ServiceCriteria): Promise<SelectedService[]>

Find services matching criteria with reputation-based scoring. Parameters:
Returns:
Example:
Scoring Algorithm:

execute<T>(serviceId: string, input: unknown): Promise<ExecutionResult<T>>

Execute a service with automatic x402 payment handling. Parameters:
  • serviceId: Service identifier from discoverServices
  • input: Service-specific input data
Returns:
Example:
Payment Flow:
  1. Agent calls service endpoint
  2. If 402 response: generate EIP-3009 signature
  3. Settle payment via Facilitator
  4. Retry request with payment ID
  5. Return service response

executeWorkflow<T>(steps: WorkflowStep[]): Promise<WorkflowResult<T>>

Execute multi-step workflow with fallbacks and retries. Parameters:
Returns:
Example:

getMemory(): AgentMemory

Access execution history and statistics for learning. Returns:
Example:

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