DISCOVER THE FUTURE OF AI AGENTSarrow_forward

claw0

calendar_todayAdded Feb 25, 2026
categoryAgent & Tooling
codeOpen Source
PythonAI AgentsWeb ApplicationAgent & ToolingDocs, Tutorials & ResourcesDeveloper Tools & CodingAutomation, Workflow & RPAProtocol, API & Integration

A progressive tutorial for building an AI Agent Gateway from scratch, covering core modules like Tool Use, WebSocket Gateway, Routing, and Reliable Delivery.

claw0 is a Python tutorial project maintained by shareAI-lab (Singapore-based open-source AI lab), released under MIT license. The project deconstructs complex AI Agent gateway systems into 10 progressive chapters (s01-s10), helping developers understand core Agent architecture concepts from scratch.

Project Positioning#

  • Problem Solved: Lowering the learning barrier for building production-grade AI Agent gateways, bridging the cognitive gap between simple demos and complex production systems
  • Use Cases: AI engineers learning Agent architecture, building private Agent prototypes, understanding best practices for Tool Use and Session management
  • Capability Boundary: Positioned as a teaching and prototyping tool; production environments should refer to the related OpenClaw project

Core Modules#

ChapterNameCore Mechanism
s01Agent Loopwhile + stop_reason (basic loop)
s02Tool UseTOOL_HANDLERS dispatch (tool routing)
s03SessionsSessionStore + JSONL (persistent sessions)
s04Multi-ChannelChannel plugin interface (multi-channel abstraction)
s05Gateway ServerWebSocket + JSON-RPC (server)
s06RoutingBinding resolution (multi-Agent routing)
s07Soul & MemorySOUL.md + MemoryStore (personality + memory)
s08HeartbeatHeartbeatRunner (proactive behavior)
s09Cron SchedulerCronService (scheduled tasks)
s10Delivery QueueDeliveryQueue + backoff (reliable delivery)

Architecture Design#

Layered Architecture:

  • Foundation Layer (s01-s03): Build single-session Agent loop, Messages list maintains context, TOOL_HANDLERS implements tool dispatch
  • Service Layer (s04-s06): Encapsulate standalone Agent as network service, WebSocket bidirectional communication, JSON-RPC protocol
  • Intelligence Layer (s07-s08): Grant Agent personality and proactivity, Markdown files define personality, dedicated thread handles heartbeat
  • Operations Layer (s09-s10): Ensure long-term system operation, Cron scheduled triggers, Delivery Queue ensures no message loss

Environment Setup#

Platform Requirements: Python 3.11+

Dependencies: anthropic>=0.39.0, python-dotenv>=1.0.0, websockets>=12.0, croniter>=2.0.0

Configuration:

  • ANTHROPIC_API_KEY: Anthropic API key (required)
  • MODEL_ID: Model ID, default claude-sonnet-4-20250514
  • ANTHROPIC_BASE_URL: Optional, supports OpenRouter and compatible services

Security Mechanisms#

  • safe_path(): Prevents path traversal attacks
  • Dangerous command blacklist: rm -rf /, mkfs, dd if=, etc.
  • Command timeout control: default 30 seconds

Quick Start#

git clone https://github.com/shareAI-lab/claw0.git && cd claw0
pip install -r requirements.txt
cp .env.example .env
# Edit .env to set ANTHROPIC_API_KEY
python agents/s01_agent_loop.py

The project includes documentation in Chinese, English, and Japanese, suitable for learners from different language backgrounds.

Related Projects

View All arrow_forward

STAY UPDATED

Get the latest AI tools and trends delivered straight to your inbox. No spam, just intelligence.

rocket_launch