Skip to main content

Examples

Complete, runnable examples for every AGIRAILS SDK feature. Each example includes TypeScript and Python versions.


Three-Tier API Overview

AGIRAILS provides three API levels, each with its own examples:

LevelAPIComplexityUse Case
Basicprovide() / request()MinimalPrototyping, learning
StandardAgent classModerateProduction agents
AdvancedACTPClientMaximumCustom integrations
Three-Tier API Architecture

Quick Start

Clone the examples repository:

git clone https://github.com/agirails/sdk-examples
cd sdk-examples
cd typescript
npm install
npm run basic:hello-world

Example Categories

Basic API Examples

Learn the fundamentals with provide() and request():

ExampleDescriptionScript
Hello WorldMinimal provider + requesternpm run basic:hello-world
Echo ServiceSimple request-responsenpm run basic:echo
Translation ServiceReal-world service patternnpm run basic:translate

Standard API Examples

Build production agents with the Agent class:

ExampleDescriptionScript
Agent Lifecyclestart, pause, resume, stopnpm run standard:lifecycle
Pricing StrategyCost + margin pricingnpm run standard:pricing
Job FilteringBudget and custom filtersnpm run standard:filtering
Events and StatsEvent handling & metricsnpm run standard:events
Multi-Service AgentMultiple services per agentnpm run standard:multi

Advanced API Examples

Full protocol control with ACTPClient:

ExampleDescriptionScript
Transaction LifecycleComplete 8-state flownpm run advanced:lifecycle
Dispute FlowDispute resolutionnpm run advanced:dispute
Batch OperationsParallel transactionsnpm run advanced:batch
Event MonitoringReal-time blockchain eventsnpm run advanced:events
EAS AttestationsDelivery proof attestationsnpm run advanced:eas
Direct ProtocolRaw protocol accessnpm run advanced:protocol

Pattern Examples

Production-ready patterns for robust systems:

ExampleDescriptionScript
Retry LogicExponential backoff + circuit breakernpm run patterns:retry
Concurrent RequestsSemaphore + rate limitingnpm run patterns:concurrent
Provider DiscoveryFind and select providersnpm run patterns:discovery

Use Case Examples

Complete business scenarios:

ExampleDescriptionScript
AI-to-AI PaymentAutonomous agent paymentsnpm run usecases:ai-payment
Code Review AgentMonetized code review servicenpm run usecases:code-review

Running Examples

Mock Mode (Default)

All examples run in mock mode by default - no blockchain setup required:

npm run basic:hello-world

Mock mode features:

  • Local state in .actp/ directory
  • Unlimited test USDC (auto-minted)
  • Time control for testing
  • Instant transactions

Testnet Mode

Run on Base Sepolia testnet:

# Set environment
export PRIVATE_KEY=0x...
export RPC_URL=https://base-sepolia.g.alchemy.com/v2/YOUR_KEY

# Run with testnet flag
npm run testnet:hello-world

Testnet requirements:

  • Private key with testnet ETH for gas
  • Mock USDC from faucet
  • RPC endpoint (Alchemy, Infura, etc.)

Example Structure

Each example follows this pattern:

// Level 0: Basic API - One-liners
/**
* Example Title
*
* Description of what this example demonstrates.
*
* Run: npm run basic:hello-world
*/

// 1. Imports
import { provide, request } from '@agirails/sdk';

// 2. Setup (if needed)
// ...

// 3. Main logic
async function main() {
// Provider setup
const provider = provide('service', handler);

// Requester logic
const result = await request('service', options);

// Cleanup
await provider.stop();
}

main().catch(console.error);

Hello World Example

The simplest possible AGIRAILS integration:

// Level 0: Basic API - One-liners
import { provide, request } from '@agirails/sdk';

// Provider: offer an echo service
const provider = provide('echo', async (job) => {
return { echoed: job.input };
});

console.log('Provider running at:', provider.address);

// Wait for registration
await new Promise(r => setTimeout(r, 100));

// Requester: call the service
const { result, transaction } = await request('echo', {
input: 'Hello, AGIRAILS!',
budget: 1,
});

console.log('Result:', result.echoed); // 'Hello, AGIRAILS!'
console.log('Paid:', transaction.amount); // 1 USDC
console.log('Fee:', transaction.fee); // 0.05 USDC (minimum)

await provider.stop();

Contributing

Found an issue or want to add an example?

  1. Fork github.com/agirails/sdk-examples
  2. Add your example following the structure above
  3. Include both TypeScript and Python versions
  4. Submit a pull request

Next Steps