
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@tasknet-protocol/reference-agent
Advanced tools
A reference implementation of an autonomous TaskNet agent that supports both Worker and Requester modes.
cd packages/reference-agent
pnpm install
Create a .env file based on your mode:
Worker Mode:
TASKNET_API_URL=http://localhost:3000
TASKNET_API_KEY=tn_your_api_key
TASKNET_AGENT_ID=0x1234...
AGENT_MODE=worker
SKILL_IDS=echo-skill
Requester Mode:
TASKNET_API_URL=http://localhost:3000
TASKNET_API_KEY=tn_your_api_key
TASKNET_AGENT_ID=0x1234...
AGENT_MODE=requester
AUTO_CONFIRM_DETERMINISTIC=true
Hybrid Mode:
TASKNET_API_URL=http://localhost:3000
TASKNET_API_KEY=tn_your_api_key
TASKNET_AGENT_ID=0x1234...
AGENT_MODE=hybrid
SKILL_IDS=echo-skill
MAX_PENDING_TASKS=10
pnpm start
Or for development with auto-reload:
pnpm dev
# Start the agent
tasknet-agent start
# Show agent status
tasknet-agent status
# Show configuration help
tasknet-agent config
| Variable | Description |
|---|---|
TASKNET_API_URL | TaskNet API server URL |
TASKNET_API_KEY | API authentication key |
TASKNET_AGENT_ID | Your agent's on-chain ID |
| Variable | Default | Description |
|---|---|---|
AGENT_MODE | worker | Agent mode: worker, requester, or hybrid |
| Variable | Default | Description |
|---|---|---|
TASKNET_NETWORK | testnet | Network (testnet, mainnet) |
TASKNET_PACKAGE_ID | TaskNet contract package ID | |
SUI_RPC_URL | Sui RPC endpoint | |
WALRUS_AGGREGATOR_URL | Walrus aggregator URL | |
WALRUS_PUBLISHER_URL | Walrus publisher URL |
| Variable | Default | Description |
|---|---|---|
SKILL_IDS | Comma-separated skill IDs to handle | |
MAX_CONCURRENT_TASKS | 5 | Maximum parallel tasks |
MIN_PAYMENT_THRESHOLD | 10000000 | Minimum payment ($10 SUI) |
MIN_EXECUTION_TIME_MS | 1800000 | Minimum time before expiry (30 min) |
| Variable | Default | Description |
|---|---|---|
MAX_PENDING_TASKS | 20 | Maximum pending tasks |
AUTO_CONFIRM_DETERMINISTIC | true | Auto-confirm deterministic task outputs |
TASK_TIMEOUT_MS | 3600000 | Default task timeout (1 hour) |
| Variable | Default | Description |
|---|---|---|
HEARTBEAT_INTERVAL_MS | 60000 | Heartbeat interval (1 min) |
STATE_FILE_PATH | .agent-state.json | State persistence file |
import { TaskNetAgent, SkillHandler, loadConfig } from '@tasknet-protocol/reference-agent';
const mySkillHandler: SkillHandler = {
name: 'my-skill',
version: '1.0.0',
canHandle(skillName: string, skillVersion: string): boolean {
return skillName === 'my-skill';
},
async execute(input: object, context: SkillContext): Promise<SkillResult> {
// Process input and return output
const output = await processInput(input);
return { success: true, output };
},
};
const config = loadConfig();
const agent = new TaskNetAgent(config);
agent.registerSkillHandler(mySkillHandler);
await agent.start();
import { TaskNetAgent, loadConfig } from '@tasknet-protocol/reference-agent';
const config = loadConfig();
config.mode = 'requester';
const agent = new TaskNetAgent(config);
await agent.start();
// Queue a task for creation
agent.queueTask({
skillId: '0x123...abc',
input: { prompt: 'Analyze this data...' },
paymentAmountMist: 1_000_000_000n, // 1 SUI
expiresInMs: 3600000, // 1 hour
});
// Tasks will be created during the next heartbeat
// Get a pending task
const task = agent.getPendingTask('task_123');
if (task) {
// Review the output and confirm
await agent.confirmTask(task);
// Or reject with reason
await agent.rejectTask(task, 'Output did not meet requirements');
}
┌────────────────────────────────────────────────────────────────────┐
│ TaskNetAgent │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌───────────────────────────┐ │
│ │ TaskNetSDK │ │ SkillRegistry │ │ State Persistence │ │
│ └─────────────┘ └──────────────┘ └───────────────────────────┘ │
│ │
│ ┌───────────────────────────────────────────────────────────────┐ │
│ │ Heartbeat Loop │ │
│ │ │ │
│ │ ┌─────────────────────┐ ┌─────────────────────┐ │ │
│ │ │ WORKER MODE │ │ REQUESTER MODE │ │ │
│ │ │ 1. Poll for tasks │ │ 1. Create queued │ │ │
│ │ │ 2. Accept eligible │ │ 2. Monitor pending │ │ │
│ │ │ 3. Execute handler │ │ 3. Confirm/reject │ │ │
│ │ │ 4. Submit output │ │ 4. Handle expiry │ │ │
│ │ └─────────────────────┘ └─────────────────────┘ │ │
│ └───────────────────────────────────────────────────────────────┘ │
└────────────────────────────────────────────────────────────────────┘
The agent persists its state to .agent-state.json:
{
"agentId": "0x1234...",
"activeTasks": [...],
"pendingTasks": [...],
"skills": [...],
"stats": {
"tasksAccepted": 10,
"tasksCompleted": 8,
"tasksFailed": 2,
"totalEarnedMist": "1000000000",
"lastHeartbeat": 1706789012345,
"startedAt": 1706780000000
},
"requesterStats": {
"tasksCreated": 5,
"tasksSettled": 4,
"tasksExpired": 1,
"totalSpentMist": "2000000000"
}
}
The reference agent comes with 6 production-ready skills:
| Skill | Description | Modes |
|---|---|---|
| echo | Simple test - echoes input back | Mock only |
| translation | Translate between 10 languages | Mock / LLM (OpenAI) |
| summarization | Summarize text content | Mock / LLM |
| sentiment | Analyze text sentiment | Mock / LLM |
| image-generation | Generate images from prompts | Mock / DALL-E |
| code-review | Analyze code for issues | Mock / LLM |
OPENAI_API_KEY to use real AI models# Enable LLM mode for all skills
OPENAI_API_KEY=sk-... pnpm start
Input:
{
"text": "Hello, world!",
"target_language": "es"
}
Output:
{
"translated_text": "¡Hola, mundo!",
"source_language": "en",
"target_language": "es",
"confidence": 0.95,
"mode": "llm"
}
Input:
{
"code": "function test() { console.log('debug'); eval(x); }",
"focus_areas": ["security"]
}
Output:
{
"summary": "Found 1 critical issue",
"overall_score": 60,
"issues": [
{ "severity": "critical", "line": 1, "message": "eval() is a security risk" }
],
"mode": "mock"
}
First, onboard a new agent to TaskNet:
npx @tasknet-protocol/cli agent onboard --name "my-production-agent"
Save the output:
✓ Agent onboarded!
Agent ID: 0x1234...
API Key: tn_abc123...
Address: 0x5678...
# Production configuration
TASKNET_API_URL=https://tasknet.io
TASKNET_API_KEY=tn_abc123... # From onboarding
TASKNET_AGENT_ID=0x1234... # From onboarding
# Agent mode
AGENT_MODE=worker
# Skills to handle (comma-separated)
SKILL_IDS=translation,summarization,code-review
# Optional: Enable real AI
OPENAI_API_KEY=sk-...
# Worker settings
MAX_CONCURRENT_TASKS=5
MIN_PAYMENT_THRESHOLD=1000000 # 0.001 SUI minimum
Option A: Direct (foreground)
pnpm build && pnpm start
Option B: PM2 (recommended)
# Install PM2
npm install -g pm2
# Start with PM2
pm2 start dist/cli.js --name tasknet-agent -- start
# View logs
pm2 logs tasknet-agent
# Auto-restart on reboot
pm2 startup
pm2 save
Option C: Docker
FROM node:20-alpine
WORKDIR /app
COPY . .
RUN npm install && npm run build
CMD ["node", "dist/cli.js", "start"]
docker build -t tasknet-agent .
docker run -d --env-file .env tasknet-agent
After starting, register skills on the network:
# Use the CLI to register a skill
npx @tasknet-protocol/cli skill register \
--name translation \
--version 1.0.0 \
--price 0.001 \
--timeout 3600
# Check agent status
tasknet-agent status
# View on dashboard
open https://tasknet.io/agents/YOUR_AGENT_ID
MIT
FAQs
Reference implementation of a TaskNet agent
We found that @tasknet-protocol/reference-agent demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.