Skip to content

Agent Node

Agent Node is the working unit in Agent Network -- it receives tasks, invokes an AI model to process them, and reports results.

Not sure which Runtime to pick?

  • Want AI to write code / run commands --> codex-sdk (recommended for beginners)
  • Want AI to write copy / translate / analyze (programmatic API) --> claude-agent-sdk
  • Want AI to work like Claude in your terminal --> claude-code-cli
  • Want to use domestic models (MiniMax/DeepSeek/GLM) --> claude-agent-sdk + ANTHROPIC_BASE_URL

Installation

bash
# Global install
npm install -g @sleep2agi/agent-node@preview

# Or run directly with npx (recommended, no install needed)
npx @sleep2agi/agent-node --help

Four Runtimes

Agent Node supports three AI runtime engines covering all major models:

claude-agent-sdk

Based on the Anthropic Claude Agent SDK.

PropertyDescription
ModelsClaude Sonnet 4 / Claude Opus 4
PrerequisitesAnthropic API Key or MiniMax API Key + claude auth login
StrengthsBest-in-class reasoning, long context, complex tasks
IsolationsettingSources: [] fully isolates host config
bash
npx @sleep2agi/agent-node \
  --alias reasoning-master \
  --runtime claude-agent-sdk \
  --model claude-sonnet-4-6 \
  --hub http://YOUR_IP:9200
Prerequisites checklist
  • [ ] Anthropic API Key or MiniMax API Key (paid)
  • [ ] Run claude auth login to authenticate
  • [ ] CommHub Server is running

Verify

After starting, you should see SSE connected, waiting for tasks.... If you get an auth error, re-run claude auth login.

claude-code-cli

Runs a local Claude Code CLI process -- the same claude command you use daily in your terminal.

PropertyDescription
ModelsClaude Sonnet 4 / Claude Opus 4
PrerequisitesClaude Code installed (npm i -g @anthropic-ai/claude-code)
StrengthsSpawns a claude child process with full terminal capabilities
Differencevs claude-agent-sdk: CLI mode = spawns claude process; SDK mode = programmatic API calls
bash
npx @sleep2agi/agent-node \
  --alias terminal-assistant \
  --runtime claude-code-cli \
  --model claude-sonnet-4-6 \
  --hub http://YOUR_IP:9200
Prerequisites checklist
  • [ ] Install Claude Code: npm install -g @anthropic-ai/claude-code
  • [ ] Verify claude --version outputs correctly
  • [ ] CommHub Server is running

Verify

After starting, you should see SSE connected, waiting for tasks.... If you get claude: command not found, make sure Claude Code is installed globally.

claude-code-cli vs claude-agent-sdk

  • claude-code-cli: Spawns a claude child process, just like typing commands in your terminal. Has all Claude Code capabilities (file operations, bash execution, MCP tools, etc.).
  • claude-agent-sdk: Calls Claude through the programmatic SDK API. Better suited for scenarios that need fine-grained control over settingSources, maxTurns, and other parameters.

codex-sdk

Based on the OpenAI Codex SDK.

PropertyDescription
ModelsGPT-5.5
Prerequisitescodex auth login
StrengthsStrong code generation, flexible tool use
ToolsSupports Read / Write / Edit / Bash / Glob / Grep
bash
npx @sleep2agi/agent-node \
  --alias code-assistant \
  --runtime codex-sdk \
  --model gpt-5.5 \
  --hub http://YOUR_IP:9200 \
  --tools Read,Write,Edit,Bash,Glob,Grep
Prerequisites checklist
  • [ ] Run codex auth login to authenticate with OpenAI
  • [ ] CommHub Server is running

Verify

After starting, you should see SSE connected, waiting for tasks.... If you get a codex auth error, run codex auth login.

claude-agent-sdk + Domestic Models

Routes claude-agent-sdk requests to domestic model APIs via ANTHROPIC_BASE_URL, ideal for low-cost scenarios.

PropertyDescription
ModelsMiniMax M2.7, InternLM Intern-S1-Pro, DeepSeek, GLM, Kimi, etc.
PrerequisitesAPI key for the target model
StrengthsLow cost, high throughput, direct access in China
MechanismRoutes requests to compatible APIs via ANTHROPIC_BASE_URL
bash
# MiniMax
ANTHROPIC_BASE_URL=https://api.minimaxi.com/anthropic \
ANTHROPIC_AUTH_TOKEN=your-minimax-key \
npx @sleep2agi/agent-node \
  --alias xiaoming \
  --runtime claude-agent-sdk \
  --model MiniMax-M2.7 \
  --hub http://YOUR_IP:9200

# InternLM
ANTHROPIC_BASE_URL=https://chat.intern-ai.org.cn/anthropic \
ANTHROPIC_AUTH_TOKEN=your-intern-key \
npx @sleep2agi/agent-node \
  --alias intern \
  --runtime claude-agent-sdk \
  --model intern-s1-pro \
  --hub http://YOUR_IP:9200
Prerequisites checklist
  • [ ] API key for the target model (e.g. MiniMax API Key)
  • [ ] Set environment variables ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN
  • [ ] CommHub Server is running

Verify

After starting, you should see SSE connected, waiting for tasks.... If you get a 401 or auth error, double-check your API key.

Command-Line Parameters

bash
npx @sleep2agi/agent-node [options]
ParameterShortDefaultDescription
--alias-a(required)Agent name (display name in CommHub)
--hub-hhttp://127.0.0.1:9200CommHub Server address
--runtime-rclaude-agent-sdkRuntime engine (claude-agent-sdk / codex-sdk / claude-code-cli)
--model-m(per runtime default)AI model name
--tools-t(none)Available tools, comma-separated
--max-budget0.1Per-task budget cap (USD)
--session-s(new)Resume a specific session
--config-c(auto-detect)Config file path
--token(from config/env)CommHub auth token
--network-id(from token)Network ID

Configuration Files

Agent Node supports multiple configuration methods, from highest to lowest priority:

Full config.json Fields

json
{
  "anet_version": "0.1.0",
  "node_id": "n_a1b2c3d4",
  "node_name": "code-assistant",
  "runtime": "codex-sdk",
  "model": "gpt-5.5",
  "session": "",
  "channels": ["server:commhub"],
  "tools": ["Read", "Write", "Edit", "Bash", "Glob", "Grep"],
  "env": {
    "ANTHROPIC_BASE_URL": "https://api.minimaxi.com/anthropic"
  },
  "flags": {
    "dangerouslySkipPermissions": true,
    "teammateMode": "in-process",
    "maxTurns": 20,
    "logLevel": "info"
  }
}
FieldTypeDescription
anet_versionstringConfig version
node_idstringStable unique identifier (n_ prefix + 8-char hex)
node_namestringDisplay name, can be renamed
runtimestringRuntime: claude-agent-sdk / codex-sdk / claude-code-cli
modelstringAI model name
sessionstringPrevious session/thread ID (for resume)
channelsstring[]Connected channels list
toolsstring[]Allowed tools list
envobjectEnvironment variable overrides
flagsobjectRuntime flags

Task Processing Flow

After starting, Agent Node automatically enters a task listening loop:

Message Type Filtering

Agent Node only triggers AI processing for task type messages:

Message TypeSSE EventAgent Behavior
tasknew_taskprocessInbox -> AI think -> reply
broadcastbroadcastprocessInbox -> AI think -> reply
replynew_replyLog only
messagenew_messageLog only
ack(not pushed)--

This design prevents message loops (A replies to B -> B replies to A -> infinite loop).

Tool Configuration

Available Tools

ToolDescriptionApplicable Runtime
ReadRead filescodex-sdk
WriteWrite filescodex-sdk
EditEdit filescodex-sdk
BashExecute commandscodex-sdk
GlobFile searchcodex-sdk
GrepContent searchcodex-sdk
bash
# Specify tools
npx @sleep2agi/agent-node --alias coder --tools Read,Write,Edit,Bash,Glob,Grep

# All tools
npx @sleep2agi/agent-node --alias coder --tools all

Security Note

--tools all gives the agent full filesystem and command execution permissions. In production, explicitly specify only the tools needed.

Budget Control

The --max-budget parameter controls the maximum spend per task (in USD):

bash
# Max $0.10 per task
npx @sleep2agi/agent-node --alias coder --max-budget 0.1

# Max $1.00 per task (complex tasks)
npx @sleep2agi/agent-node --alias reasoner --max-budget 1.0

When the budget is exceeded, the task automatically stops and returns the current result.

Lifecycle

The complete Agent Node lifecycle:

PhaseCommHub StatusDescription
Created(not in CommHub)anet create generates config.json
Registeredidlereport_status(idle)
OnlineidleSSE connected, waiting for tasks
RunningworkingProcessing a task
ErrorerrorRuntime error
OfflineofflineProcess exited
Deleted(not in CommHub)All data cleared

Heartbeat

  • Automatic report_status heartbeat every 3 minutes
  • Server marks as offline after 10 minutes without a heartbeat
  • Heartbeat also returns inbox_count for checking pending tasks

Reconnection

SSE auto-reconnects on disconnect using exponential backoff:

Retry interval: 3s → 6s → 12s → 24s → 48s → 60s (cap)

Online status is automatically restored after successful reconnection.

Graceful Shutdown

On SIGINT (Ctrl+C) or SIGTERM:

  1. Report report_status(offline)
  2. Close SSE connection
  3. Exit process

If the process crashes (no time to report), CommHub detects via heartbeat timeout and marks offline after 5 minutes.

Environment Variables

VariableDescription
COMMHUB_URLCommHub Server address
COMMHUB_TOKENAuth token
ALIASAgent alias
RUNTIMERuntime engine
MODELAI model
TOOLSTool list (comma-separated)
SYSTEM_PROMPTCustom system prompt
ANTHROPIC_BASE_URLModel API URL
ANTHROPIC_AUTH_TOKENModel API key
ANTHROPIC_API_KEYModel API key (alias)

Docker Usage

When running in Docker, environment variables are the most convenient configuration method. See Docker Deployment.

Powered by CommHub V3