Model or dataset
voocel/openclaw-mini avatar
voocel/openclaw-mini

openclaw-mini: A Reading Copy of the OpenClaw Agent Kernel in TypeScript

🦞 OpenClaw 核心架构的极简复现,涵盖 sessionKey 会话域、队列串行、工具化记忆检索、按需上下文加载、可扩展技能与主动心跳唤醒机制

699 stars95 forksTypeScriptMIT

At a glance

What is it?
openclaw-mini reimplements the core of OpenClaw's agent architecture as a small TypeScript study project. It is a teaching artifact, not a production runtime, and the README says so explicitly.
Who is it for?
Adopt openclaw-mini if you are an engineer who learns architecture by reading code and wants the four threads (CLI, agent loop, session, gateway) in one repository you can run with pnpm dev. Do not adopt it as a production agent runtime: the README lists API compatibility, channel/provider coverage and production hardening as non-goals, and the project is at v0.1.1.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 107 days ago.
What is it written in?
Mainly TypeScript, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on September 15, 2026, and from our analysis. They are not legal advice.

DEEP OPEN-SOURCE ANALYSIS

What openclaw-mini is trying to explain, and to whom

The README opens with a blunt claim about the state of agent tutorials: most of them show a while loop over tool calls and stop there. The author's position is that this loop is not an agent architecture. A production agent, in this framing, needs session persistence, context management, long-term memory, a skill system and a wake-up mechanism, and those pieces are what the repository reproduces at small scale. The stated goal is to explain the design points of the OpenClaw kernel across four threads the README names: CLI, Agent Loop, Session, Context and Gateway. The non-goals matter just as much. There is no promise of 1:1 API compatibility with the main OpenClaw repository, no coverage of every channel, provider, plugin or operational feature, and no attempt to port production hardening, permissions or compatibility details. That framing is honest about the artifact's status. This is a repository you read to understand why a system is shaped the way it is, and the README says the comments preserve the why rather than only shipping runnable code. The audience is therefore narrow: engineers who already build agents and want a smaller specimen of a larger one, not teams looking for a dependency to put behind a product.

The four-layer module map and what each layer buys you

The repository is organized into four layers, and the README recommends reading them in the order core, extended, gateway, engineering. The core layer holds what the README calls capabilities every agent needs: agent.ts as the entry point with subscribe and emit event dispatch, agent-loop.ts with the two-level loop, agent-events.ts defining a discriminated union of twenty MiniAgentEvent types with async push and pull, session.ts for JSONL persistence, context/loader.ts for loading bootstrap files such as AGENTS.md on demand, context/pruning.ts for a three-stage progressive trim, context/compaction.ts for adaptive chunked summarization, tools/*.ts for the tool abstraction plus ten built-in tools, and provider/*.ts for the multi-model adapter layer built on pi-ai. The extended layer is described as OpenClaw-specific rather than universally required: memory.ts for long-term memory with keyword retrieval and relevance ranking, skills.ts for SKILL.md frontmatter plus trigger-word matching, and heartbeat.ts as a two-layer design combining wake request merging with runner scheduling. The engineering layer is explicitly marked skippable for learners and contains session-key.ts, tool-policy.ts, command-queue.ts, session-tool-result-guard.ts, context-window-guard.ts and sandbox-paths.ts. The gateway layer is the advanced reading: protocol.ts with three frame types, server.ts with the HTTP and WebSocket service, handlers.ts with six RPC methods, client.ts with reconnection and heartbeat monitoring, and gateway-cli.ts. The layer split is the most useful thing in the README, because it tells you which files are load-bearing for understanding and which are production scaffolding you can defer.

The two-level agent loop and why the README rejects the single while loop

The central mechanism the project demonstrates is a two-level loop. The README describes an outer loop for follow-up turns and an inner loop for tool execution plus steering injection, with the whole thing returning an EventStream that the caller consumes with for-await. The code sketch in the README shows runAgentLoop creating a stream, then an immediately invoked async function pushing events into it while the outer turn counter stays under maxOuterTurns, and finally calling stream.end with text, turns and toolCalls. The stated problem this solves is that a simple while loop cannot handle follow-up, steering injection or context overflow. Whether that is entirely true depends on how much you need those behaviours, but the design choice is coherent: by making the loop a producer into an event stream rather than a function that returns a final string, the caller can react to intermediate state. The README shows the subscription pattern aligned with pi-agent-core's Agent.subscribe, where agent.subscribe takes a callback and returns an unsubscribe function, and the callback switches on event.type for cases like message_delta for streaming text, tool_execution_start with toolName and args, and agent_error for run failures. Twenty event types is a lot for a minimal reproduction, and that is a deliberate trade: the event surface is where the interesting coupling lives, so shrinking it would hide the architecture. The cost is that you cannot read agent-loop.ts in isolation; you need agent-events.ts open beside it.

Session persistence: the dual-write rule and the empty-session guard

session.ts addresses a concrete question the README poses: how does an agent recover conversational context after a restart? The answer is a dual-write strategy with an in-memory cache plus disk persistence. The README quotes the append method, which pushes an entry into state.entries for zero-I/O reads, then checks whether the session has already written an assistant message. The first assistant message triggers a flag and a full rewrite of the session file including the header and entries. The comment in the code explains the intent: avoid writing an empty session to disk. That is a small decision with a visible consequence. A session that only ever receives user messages, or that errors before the model replies, leaves no file behind. For a learning project this is the right kind of detail, because it shows that persistence is not just append-to-file but a policy about when a session counts as real. The README excerpt is truncated mid-branch, so the behaviour after the first assistant message is not fully documented in the supplied material. If you care about the exact write path for subsequent messages, read session.ts directly; do not infer it from the README.

Getting it running: clone, env, and the commands that actually exist

Setup follows a conventional pnpm workflow. The README gives: git clone git@github.com:voocel/openclaw-mini.git, cd openclaw-mini, pnpm install, cp .env.example .env. You must then put at least one usable model key in .env before anything meaningful runs. The first validation steps are pnpm test and pnpm dev. To watch the gateway's ACK-then-stream path specifically, the README points to pnpm example:gateway. For standalone development the sequence is pnpm install, pnpm test, pnpm build. The local CLI has three entry points: pnpm dev, pnpm gateway, and pnpm gateway:connect, which map to the serve and connect modes of gateway-cli.ts. Before publishing or packaging, the README lists pnpm test, pnpm build and pnpm pack:check as a self-check sequence. The config surface described in the material is thin: .env with a model key is the only file-level configuration named, and provider selection happens in code, as the Agent constructor example shows with apiKey and provider: "anthropic". There is no documented config file for tool policy, queue lanes or sandbox paths, even though those modules exist. That gap is worth noting: the engineering layer is present as code but not exposed as documented configuration in the README.

Where the minimal reproduction stops being enough

The most important limitation is stated by the author, not discovered by a reader. The project is not API-compatible with OpenClaw, does not cover all channels, providers, plugins or operational capabilities, and does not carry over production protections, permissions and compatibility details. So any behaviour you rely on here may differ in the main repository, and any hardening you need is something you would add. A second limitation is structural: several modules in the engineering layer exist precisely because agent systems fail in specific ways. session-tool-result-guard.ts backfills missing tool results, context-window-guard.ts protects against context window overflow, and command-queue.ts controls concurrency with session serialization and global parallelism. The README classifies this layer as skippable for learners, which is reasonable for reading, but it means the minimal path you run with pnpm dev is not the path that has those guards wired in. If you strip the engineering layer out of your mental model, you will also strip out the failure modes it was written to absorb. The material does not say which of these guards are active in the default pnpm dev flow, so treat that as unverified and check the wiring yourself. A third limitation is scale: the README cites the main OpenClaw repository as over 430,000 lines. A reproduction of that at this size necessarily omits the long tail, and the long tail is usually where production surprises live.

How this differs from the frameworks you would otherwise reach for

The obvious comparison is a general-purpose agent framework such as LangChain or the Vercel AI SDK, and the difference is one of purpose rather than features. Those libraries are meant to be depended on: you import their abstractions and your application lives on top. openclaw-mini is meant to be read and modified. Its abstractions are shaped to mirror a specific larger system, down to file names and module responsibilities, and the README maps each file to its counterpart in OpenClaw, for example agent.ts to agent.js and context/pruning.ts to context-pruning/pruner.ts. That mapping is the product. You cannot get it from a general framework, because a general framework has no single upstream architecture to explain. The trade is that openclaw-mini is a worse dependency: it is at v0.1.1, the README disclaims compatibility, and the provider layer is built on pi-ai rather than being self-contained. If your goal is to ship an agent this quarter, a framework with a stability contract is the better tool. If your goal is to understand how session domains, queue serialization, tool-based memory retrieval, on-demand context loading, extensible skills and proactive heartbeat wake-up fit together in one system, this repository is a shorter path than reading a 430,000-line codebase. The README's own positioning supports that reading: it is a reproduction for learning system-level design, not a runtime.

Maintenance, licence and what to check before you build on it

The repository is MIT licensed, which permits commercial use, modification and redistribution provided the copyright notice and licence text are preserved. That is the standard permissive position and it is the same licence the surrounding ecosystem usually expects. It is not legal advice; if you are vendoring the code into a product, have counsel confirm the notice requirements and check the licences of the transitive dependencies, particularly pi-ai, which the README names as the basis of the provider layer. Maintenance signals in the supplied material are limited to releases: v0.1.0 and v0.1.1, both dated 2026-05-31, with the last push on the same day as v0.1.1. Two releases on one day is an initial publication pattern, not a track record, and the material gives no information about issue response, contributor count or roadmap. The upgrade cost of a project like this is mostly your own: because the README disclaims 1:1 compatibility with OpenClaw, you cannot assume that a change upstream maps cleanly onto a change here, and because the code is the documentation, a version bump may mean re-reading modules rather than reading a changelog. Before adopting it as anything more than study material, verify the licence file in the repository matches the MIT declaration, confirm that the provider layer's dependency on pi-ai is acceptable in your dependency policy, and read the engineering-layer guards to see which of them your use case actually requires.

Editorial conclusion

Adopt openclaw-mini if you are an engineer who learns architecture by reading code and wants the four threads (CLI, agent loop, session, gateway) in one repository you can run with pnpm dev. Do not adopt it as a production agent runtime: the README lists API compatibility, channel/provider coverage and production hardening as non-goals, and the project is at v0.1.1. Before committing, verify three things in the tree: that the tool policy in tool-policy.ts matches the access levels your workload needs, that the pruning order in context/pruning.ts is the one you expect, and that the gateway's challenge handshake fits your transport. Nothing in the README substitutes for reading those files.

Official sources

  1. Issues
  2. License: MIT
  3. README
  4. Releases
  5. voocel/openclaw-mini on GitHub
Community notes

Community notes