[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-74126":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":10,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":24,"hasPages":22,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":16,"starSnapshotCount":16,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},74126,"claw0","shareAI-lab\u002Fclaw0","shareAI-lab","0 - 1 learn OpenClaw: sections to build an claw-AI agent from scratch","",null,"Python",2882,338,10,5,0,42,106,328,126,29.59,false,"main",true,[],"2026-06-12 02:03:22","[English](README.md) | [中文](README.zh.md) | [日本語](README.ja.md)  \n# claw0\n\n\n**From Zero to One: Build an AI Agent Gateway**\n\n> 10 progressive sections -- every section is a single, runnable Python file.\n> 3 languages (English, Chinese, Japanese) -- code + docs co-located.\n\n---\n\n## What is this?\n\nMost agent tutorials stop at \"call an API once.\" This repository starts from that while loop and takes you all the way to a production-grade gateway.\n\nBuild a minimal AI agent gateway from scratch, section by section. 10 sections, 10 core concepts, ~7,000 lines of Python. Each section introduces exactly one new idea while keeping all prior code intact. After all 10, you can read OpenClaw's production codebase with confidence.\n\n```sh\ns01: Agent Loop           -- The foundation: while + stop_reason\ns02: Tool Use             -- Let the model call tools: dispatch table\ns03: Sessions & Context   -- Persist conversations, handle overflow\ns04: Channels             -- Telegram + Feishu: real channel pipelines\ns05: Gateway & Routing    -- 5-tier binding, session isolation\ns06: Intelligence         -- Soul, memory, skills, prompt assembly\ns07: Heartbeat & Cron     -- Proactive agent + scheduled tasks\ns08: Delivery             -- Reliable message queue with backoff\ns09: Resilience           -- 3-layer retry onion + auth profile rotation\ns10: Concurrency          -- Named lanes serialize the chaos\n```\n\n## Architecture\n\n```\n+------------------- claw0 layers -------------------+\n|                                                     |\n|  s10: Concurrency  (named lanes, generation track)  |\n|  s09: Resilience   (auth rotation, overflow compact)|\n|  s08: Delivery     (write-ahead queue, backoff)     |\n|  s07: Heartbeat    (lane lock, cron scheduler)      |\n|  s06: Intelligence (8-layer prompt, hybrid memory)  |\n|  s05: Gateway      (WebSocket, 5-tier routing)      |\n|  s04: Channels     (Telegram pipeline, Feishu hook) |\n|  s03: Sessions     (JSONL persistence, 3-stage retry)|\n|  s02: Tools        (dispatch table, 4 tools)        |\n|  s01: Agent Loop   (while True + stop_reason)       |\n|                                                     |\n+-----------------------------------------------------+\n```\n\n## Section Dependencies\n\n```\ns01 --> s02 --> s03 --> s04 --> s05\n                 |               |\n                 v               v\n                s06 ----------> s07 --> s08\n                 |               |\n                 v               v\n                s09 ----------> s10\n```\n\n- s01-s02: Foundation (no dependencies)\n- s03: Builds on s02 (adds persistence to the tool loop)\n- s04: Builds on s03 (channels produce InboundMessages for sessions)\n- s05: Builds on s04 (routes channel messages to agents)\n- s06: Builds on s03 (uses sessions for context, adds prompt layers)\n- s07: Builds on s06 (heartbeat uses soul\u002Fmemory for prompt)\n- s08: Builds on s07 (heartbeat output flows through delivery queue)\n- s09: Builds on s03+s06 (reuses ContextGuard for overflow, model config)\n- s10: Builds on s07 (replaces single Lock with named lane system)\n\n## Quick Start\n\n```sh\n# 1. Clone and enter\ngit clone https:\u002F\u002Fgithub.com\u002FshareAI-lab\u002Fclaw0.git && cd claw0\n\n# 2. Install dependencies\npip install -r requirements.txt\n\n# 3. Configure\ncp .env.example .env\n# Edit .env: set ANTHROPIC_API_KEY and MODEL_ID\n\n# 4. Run any section (pick your language)\npython sessions\u002Fen\u002Fs01_agent_loop.py    # English\npython sessions\u002Fzh\u002Fs01_agent_loop.py    # Chinese\npython sessions\u002Fja\u002Fs01_agent_loop.py    # Japanese\n```\n\n## Learning Path\n\nEach section adds exactly one new concept. All prior code stays intact:\n\n```\nPhase 1: FOUNDATION     Phase 2: CONNECTIVITY     Phase 3: BRAIN        Phase 4: AUTONOMY       Phase 5: PRODUCTION\n+----------------+      +-------------------+     +-----------------+   +-----------------+   +-----------------+\n| s01: Loop      |      | s03: Sessions     |     | s06: Intelligence|  | s07: Heartbeat  |   | s09: Resilience |\n| s02: Tools     | ---> | s04: Channels     | --> |   soul, memory, | ->|   & Cron        |-->|   & Concurrency |\n|                |      | s05: Gateway      |     |   skills, prompt |  | s08: Delivery   |   | s10: Lanes      |\n+----------------+      +-------------------+     +-----------------+   +-----------------+   +-----------------+\n while + dispatch        persist + route            personality + recall  proactive + reliable  retry + serialize\n```\n\n## Section Details\n\n| # | Section | Core Concept | Lines |\n|---|---------|-------------|-------|\n| 01 | Agent Loop | `while True` + `stop_reason` -- that's an agent | ~175 |\n| 02 | Tool Use | Tools = schema dict + handler map. Model picks a name, you look it up | ~445 |\n| 03 | Sessions | JSONL: append on write, replay on read. Too big? Summarize old parts | ~890 |\n| 04 | Channels | Every platform differs, but they all produce the same `InboundMessage` | ~780 |\n| 05 | Gateway | Binding table maps (channel, peer) to agent. Most specific wins | ~625 |\n| 06 | Intelligence | System prompt = files on disk. Swap files, change personality | ~750 |\n| 07 | Heartbeat & Cron | Timer thread: \"should I run?\" + queue work alongside user messages | ~660 |\n| 08 | Delivery | Write to disk first, then send. Crashes can't lose messages | ~870 |\n| 09 | Resilience | 3-layer retry onion: auth rotation, overflow compaction, tool-use loop | ~1130 |\n| 10 | Concurrency | Named lanes with FIFO queues, generation tracking, Future-based results | ~900 |\n\n## Repository Structure\n\n```\nclaw0\u002F\n  README.md              English README\n  README.zh.md           Chinese README\n  README.ja.md           Japanese README\n  .env.example           Configuration template\n  requirements.txt       Python dependencies\n  sessions\u002F              All teaching sessions (code + docs)\n    en\u002F                  English\n      s01_agent_loop.py  s01_agent_loop.md\n      s02_tool_use.py    s02_tool_use.md\n      ...                (10 .py + 10 .md)\n    zh\u002F                  Chinese\n      s01_agent_loop.py  s01_agent_loop.md\n      ...                (10 .py + 10 .md)\n    ja\u002F                  Japanese\n      s01_agent_loop.py  s01_agent_loop.md\n      ...                (10 .py + 10 .md)\n  workspace\u002F             Shared workspace samples\n    SOUL.md  IDENTITY.md  TOOLS.md  USER.md\n    HEARTBEAT.md  BOOTSTRAP.md  AGENTS.md  MEMORY.md\n    CRON.json\n    skills\u002Fexample-skill\u002FSKILL.md\n```\n\nEach language folder is self-contained: runnable Python code + documentation side by side. Code logic is identical across languages; comments and docs differ.\n\n## Prerequisites\n\n- Python 3.11+\n- An API key for Anthropic (or compatible provider)\n\n## Dependencies\n\n```\nanthropic>=0.39.0\npython-dotenv>=1.0.0\nwebsockets>=12.0\ncroniter>=2.0.0\npython-telegram-bot>=21.0\nhttpx>=0.27.0\n```\n\n## Related Projects\n\n- **[learn-claude-code](https:\u002F\u002Fgithub.com\u002FshareAI-lab\u002Flearn-claude-code)** -- A companion teaching repo that builds an agent **framework** (nano Claude Code) from scratch in 12 progressive sessions. Where claw0 focuses on gateway routing, channels, and proactive behavior, learn-claude-code dives deep into the agent's internal design: structured planning (TodoManager + nag), context compression (3-layer compact), file-based task persistence with dependency graphs, team coordination (JSONL mailboxes, shutdown\u002Fplan-approval FSM), autonomous self-organization, and git worktree isolation for parallel execution. If you want to understand how a production-grade unit agent works inside, start there.\n\n## About\n\u003Cimg width=\"260\" src=\"https:\u002F\u002Fgithub.com\u002Fuser-attachments\u002Fassets\u002Ffe8b852b-97da-4061-a467-9694906b5edf\" \u002F>\u003Cbr>\n\nScan with Wechat to fellow us,  \nor fellow on X: [shareAI-Lab](https:\u002F\u002Fx.com\u002Fbaicai003)  \n\n## License\n\nMIT\n","claw0 是一个从零开始构建AI代理网关的教程项目。该项目通过10个递进的部分，逐步引导开发者构建一个生产级的AI代理网关，每个部分都是一个独立可运行的Python文件，覆盖了从基础循环到并发处理的关键概念和技术，总计约7,000行代码。核心功能包括工具调用、会话管理、多渠道支持、智能增强、定时任务执行及消息队列等，旨在提供一套完整的解决方案来实现高效稳定的AI代理服务。适用于希望深入了解并亲手实践如何开发高级AI代理系统的开发者或团队，特别是那些对构建能够与用户进行持续互动的智能化系统感兴趣的群体。",2,"2026-06-11 03:48:55","high_star"]