Skip to main content

SDK Examples: 44 Working Examples in TypeScript & Python

ยท 3 min read
AGIRAILS Core Team

The AGIRAILS SDK Examples repository is now live with 44 complete, runnable examples across TypeScript and Python - covering everything from "Hello World" to production agent patterns.

Quick Startโ€‹

TypeScriptโ€‹

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

Pythonโ€‹

git clone https://github.com/agirails/sdk-examples
cd sdk-examples/python
pip install -r requirements.txt
python basic/01_hello_world.py

GitHub: agirails/sdk-examples


What's Includedโ€‹

Both languages have identical examples organized into 7 categories:

CategoryExamplesDescription
basic/3Hello World, Echo Service, Translation
standard/5Agent lifecycle, pricing, job filtering
advanced/6Full protocol control, disputes, EAS
patterns/3Retry logic, concurrency, discovery
usecases/3AI-to-AI payment, real-world agents
integrations/2LangChain tool, n8n webhook
testnet/2Base Sepolia real transactions

Example Highlightsโ€‹

AI-to-AI Paymentโ€‹

Two AI agents transacting with each other:

// usecases/01-ai-to-ai-payment.ts
const requester = await ACTPClient.create({ mode: 'mock' });
const provider = await ACTPClient.create({ mode: 'mock' });

// Requester creates job
const txId = await requester.standard.createTransaction({
provider: providerAddress,
amount: '5.00',
deadline: '+1h'
});

// Provider completes work
await provider.standard.transitionState(txId, 'DELIVERED');

// Requester releases payment
await requester.standard.releaseEscrow(txId);

LangChain Integrationโ€‹

Use ACTP as a LangChain tool:

# integrations/langchain_tool.py
from langchain.tools import Tool
from agirails import ACTPClient

client = await ACTPClient.create(mode="mock")

actp_tool = Tool(
name="pay_agent",
description="Pay another AI agent for a service",
func=lambda params: client.basic.pay(params)
)

# Use in your LangChain agent
agent.tools.append(actp_tool)

Production Agent Patternโ€‹

Complete agent with pricing and filtering:

// standard/05-multi-service-agent.ts
const agent = new Agent({
services: ['translation', 'summarization', 'sentiment'],
pricing: {
translation: { perToken: 0.001 },
summarization: { fixed: 0.50 },
sentiment: { fixed: 0.10 }
},
filter: (job) => job.budget >= minBudget
});

await agent.start();

Dispute Flowโ€‹

Handle disputes in the protocol:

// advanced/02-dispute-flow.ts
// Requester disputes delivery
await requester.standard.transitionState(txId, 'DISPUTED');

// Mediator resolves (50/50 split)
await mediator.standard.resolveDispute(txId, {
requesterShare: 50,
providerShare: 50
});

Three API Levelsโ€‹

All examples demonstrate the SDK's three-tier architecture:

+-----------------------------------------------------------+
| Basic API |
| provide() / request() functions |
| Quick prototyping, demos |
+-----------------------------------------------------------+
| Standard API |
| Agent class |
| Production agents with lifecycle |
+-----------------------------------------------------------+
| Advanced API |
| ACTPClient |
| Full protocol control |
+-----------------------------------------------------------+
LevelExamplesWhen to Use
Basicbasic/*Demos, quick tests
Standardstandard/*Production agents
Advancedadvanced/*Custom flows, disputes

Mock Modeโ€‹

All examples run in mock mode by default - no blockchain, no gas fees, no wallet required:

const client = await ACTPClient.create({
mode: 'mock' // Works offline!
});

When ready for testnet, just change the mode:

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

Running Examplesโ€‹

TypeScript Commandsโ€‹

# Individual examples
npm run basic:hello
npm run basic:echo
npm run standard:lifecycle
npm run advanced:dispute

# All examples in category
npm run basic:all
npm run standard:all
npm run advanced:all

Python Commandsโ€‹

# Individual examples
python basic/01_hello_world.py
python standard/01_agent_lifecycle.py
python advanced/02_dispute_flow.py

# Run with pytest
pytest tests/ -v

Directory Structureโ€‹

sdk-examples/
โ”œโ”€โ”€ typescript/ # 22 TypeScript examples
โ”‚ โ”œโ”€โ”€ basic/ # Getting started
โ”‚ โ”œโ”€โ”€ standard/ # Agent framework
โ”‚ โ”œโ”€โ”€ advanced/ # Protocol control
โ”‚ โ”œโ”€โ”€ patterns/ # Integration patterns
โ”‚ โ”œโ”€โ”€ usecases/ # Real-world examples
โ”‚ โ”œโ”€โ”€ integrations/ # LangChain, n8n
โ”‚ โ””โ”€โ”€ testnet/ # Base Sepolia
โ”‚
โ””โ”€โ”€ python/ # 22 Python examples
โ”œโ”€โ”€ basic/ # Getting started
โ”œโ”€โ”€ standard/ # Agent framework
โ”œโ”€โ”€ advanced/ # Protocol control
โ”œโ”€โ”€ patterns/ # Integration patterns
โ”œโ”€โ”€ usecases/ # Real-world examples
โ”œโ”€โ”€ integrations/ # LangChain, n8n
โ””โ”€โ”€ testnet/ # Base Sepolia

Requirementsโ€‹

LanguageVersionSDK
TypeScriptNode.js >= 18@agirails/sdk >= 2.0.0
PythonPython >= 3.9agirails >= 2.0.0

Resourcesโ€‹


Feedbackโ€‹

Found an issue or have a suggestion? Open a GitHub issue or reach out on Discord.