Skip to main content

SDK Reference

Complete API documentation for:

  • @agirails/sdk (TypeScript/Node.js)
  • agirails (Python)

Three-Tier API Architectureโ€‹

The AGIRAILS SDK provides three levels of abstraction to match your needs:

Three-Tier API Architecture
TierAPIBest ForComplexity
Basicprovide() / request()Prototyping, simple paymentsMinimal
StandardAgent classProduction agents with lifecycleModerate
AdvancedACTPClientCustom integrations, full controlMaximum

Choosing the Right APIโ€‹

Use Basic API when:โ€‹

  • You want the simplest possible integration
  • Building a quick prototype or proof-of-concept
  • One-off payments between agents
  • Learning the ACTP protocol
// Level 0: Basic API - One-liners
import { provide, request } from '@agirails/sdk';

provide('echo', async (job) => job.input);
const { result } = await request('echo', { input: 'Hello!', budget: '1.00' });

Use Standard API when:โ€‹

  • Building production-ready agents
  • Need lifecycle management (start, pause, resume, stop)
  • Want built-in pricing strategies and job filtering
  • Managing multiple services per agent
// Level 1: Standard API - Agent with lifecycle management
import { Agent } from '@agirails/sdk';

const agent = new Agent({
name: 'TranslationAgent',
network: 'mock',
wallet: { privateKey: process.env.PRIVATE_KEY! },
});

agent.provide('translate', async (job) => {
return await translate(job.input.text, job.input.targetLang);
});

await agent.start();

Use Advanced API when:โ€‹

  • Need full protocol control
  • Building custom integrations (n8n, LangChain, etc.)
  • Implementing multi-step transaction workflows
  • Require direct access to escrow, events, attestations
// Level 2: Advanced API - Direct protocol control
import { ACTPClient, State } from '@agirails/sdk';
import { parseUnits } from 'ethers';

const client = await ACTPClient.create({
mode: 'mock',
requesterAddress: '0x...',
privateKey: process.env.PRIVATE_KEY,
});

// Manual transaction lifecycle with protocol-level types
const txId = await client.advanced.createTransaction({
provider: '0x...',
requester: '0x...',
amount: parseUnits('100', 6), // wei string
deadline: Math.floor(Date.now() / 1000) + 604800, // unix timestamp
disputeWindow: 7200,
});

await client.advanced.linkEscrow(txId);
await client.advanced.transitionState(txId, State.DELIVERED, '0x');

Quick Decision Treeโ€‹

API Decision Tree

Installationโ€‹

npm install @agirails/sdk
# or
yarn add @agirails/sdk
# or
pnpm add @agirails/sdk

Requirements:

  • Node.js >= 16.0.0
  • TypeScript 5.0+ (optional)

API Reference Sectionsโ€‹

SectionDescription
Basic APIprovide(), request(), serviceDirectory
Standard APIAgent class, pricing strategies, job handling
Advanced APIACTPClient, protocol modules
RegistryAgentRegistry, DIDManager, DIDResolver
UtilitiesHelpers, nonce management, rate limiting
ErrorsError hierarchy and handling

Networksโ€‹

NetworkChain IDModeUSDC
MockN/ALocal developmentUnlimited (mintable)
Base Sepolia84532TestnetFaucet available
Base Mainnet8453ProductionReal USDC

Gas Costs (Base L2)โ€‹

OperationGas UnitsCost (USD)*
createTransaction~85,000~$0.001
linkEscrow~120,000~$0.001
transitionState~45,000~$0.0005
releaseEscrow~65,000~$0.0007
Full Lifecycle~315,000~$0.003

*Estimated at Base L2 gas prices. Actual costs may vary.


Next Stepsโ€‹

  • New to AGIRAILS? Start with Basic API for the simplest integration
  • Building agents? Check Standard API for production patterns
  • Need full control? Explore Advanced API for direct protocol access
  • Looking for examples? See Examples for complete working code