# chris-han/metaclaw architecture

> Architecture diagram of the GitHub repository chris-han/metaclaw, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/chris-han/metaclaw
- Repository: https://github.com/chris-han/metaclaw

## Overview

1. **Repository shape**
   - This is a multi-package monorepo centered on the **Python `metaclaw` runtime**, with a **TypeScript OpenClaw plugin**, an optional **memory sidecar**, a **benchmark suite**, and a large set of **skill/memory assets** used at runtime and for evaluation.

2. **Main runtime entrypoint**
   - The primary application is the `metaclaw` Python package.
   - Its top-level responsibilities are: CLI handling, configuration management, local proxy startup, agent auto-configuration, session/state tracking, and orchestration of the skills, memory, RL, and scheduler subsystems.
   - Key entry modules include `cli.py`, `launcher.py`, `api_server.py`, `setup_wizard.py`, and `scheduler.py`.

3. **Serving/data plane**
   - MetaClaw sits **in front of a personal agent or client** as a local proxy.
   - Incoming chat requests flow from the agent into MetaClaw, where the request is enriched with skills and optionally memory, then forwarded to the configured upstream LLM provider.
   - The proxy supports both **OpenAI-compatible** and **Anthropic-compatible** request shapes, which is why there are adapter and compatibility layers such as `claw_adapter.py` and `weaver_compat.py`.

4. **Agent integration boundary**
   - The repo explicitly supports multiple “claws”/clients: OpenClaw, CoPaw, IronClaw, PicoClaw, ZeroClaw, NanoClaw, NemoClaw, Hermes, and a manual/`none` mode.
   - MetaClaw’s startup path can rewrite or patch the target agent’s local config, then restart that agent so traffic routes through the MetaClaw proxy automatically.
   - This is a clear boundary between **MetaClaw-managed local configuration** and the **external personal agent runtime**.

5. **Skills subsystem**
   - Skills are short, local Markdown instructions stored under `~/.metaclaw/skills` and seeded from `memory_data/skills`.
   - At runtime, the system retrieves relevant skills and injects them into prompts.
   - After sessions, the system can summarize new learning into new skill files, so the skill library evolves over time.
   - The `metaclaw/memory` namespace also contains skill/promotion/policy logic, suggesting skill evolution is tightly coupled to memory and retrieval policy.

6. **Long-term memory subsystem**
   - The memory layer stores cross-session facts such as preferences, project state, and episodic summaries.
   - It supports retrieval modes like keyword/semantic/hybrid and has its own local storage and policy controls.
   - Memory can run in-process or be delegated to the **optional memory sidecar** package under `openclaw-metaclaw-memory/sidecar`, which exposes a local HTTP service and isolates memory reads/writes from the main proxy.

7. **RL / continual learning subsystem**
   - When RL is enabled, live conversation turns are turned into training samples, scored asynchronously by a PRM/judge model, and sent to a backend for LoRA-style fine-tuning.
   - The backend is abstracted so the same control plane can target **Tinker**, **MinT**, or **Weaver**.
   - The repo includes orchestration for batching, replay, failover, and hot-swapping updated weights back into service.
   - There is also optional **OPD** (on-policy distillation), where a teacher model supplies log-probabilities through an OpenAI-compatible completions endpoint.

8. **Scheduler and async execution**
   - The default “auto” mode adds a scheduler that defers weight updates to low-interruption windows such as sleep hours, idle periods, or Google Calendar meetings.
   - This makes the serving path and training path intentionally decoupled: users keep chatting while scoring, consolidation, and optimization run in the background.
   - The scheduler is therefore a key architectural boundary between **interactive serving** and **non-interactive learning**.

9. **Configuration, auth, and state**
   - Local state is persisted under `~/.metaclaw`, with configuration managed through `config.py`, `config_store.py`, `auth_store.py`, `cli_session_store.py`, and `runtime_state.py`.
   - The setup wizard initializes the system, while the CLI provides lifecycle commands for start/stop/status/config/auth/uninstall.
   - These stores define the persistent control plane for both runtime behavior and external provider credentials.

10. **External dependencies and service boundaries**
   - The main external systems are LLM APIs, RL training backends, optional calendar access, and optional agent runtimes.
   - The repo also supports optional compatibility packages for alternate backends and agent ecosystems, keeping those dependencies out of the core package.
   - This makes the core MetaClaw process portable while allowing specialized integrations to be added only when needed.

11. **Benchmarking and evaluation**
   - The `benchmark/` package is a separate evaluation stack with its own CLI, validators, inference/scoring/reporting commands, configs, and datasets.
   - It uses packaged daily workspace snapshots, session logs, and question sets to evaluate learning/adaptation over time.
   - This is structurally independent from the runtime proxy, but it exercises the same skill/memory/agent assumptions.

12. **Extension and packaging layer**
   - `openclaw-metaclaw-memory` is a distributable plugin package with a compiled TypeScript client plus a Python sidecar implementation.
   - `extensions/metaclaw-openclaw` is the lightweight OpenClaw integration package.
   - Together they show that MetaClaw is designed as a **core Python control plane** with **pluggable client-side integrations** and **optional isolated services**.

13. **Supporting assets, scripts, and tests**
   - `scripts/` contains experiment runners, ablations, benchmark helpers, and end-to-end test orchestration.
   - `tests/` covers CLI behavior, launcher behavior, memory, scheduler, rollout, and utility functions.
   - The large `memory_data/` tree acts as bundled seed content: skills plus policy/data used to bootstrap the system.

14. **High-level architectural flow**
   - User chats with a supported agent.
   - The agent routes requests through MetaClaw’s local proxy.
   - The proxy injects skills and optionally long-term memory.
   - Responses are returned immediately.
   - In parallel, conversation data is summarized, stored, scored, and optionally used for RL training and skill evolution.
   - Scheduler and backend abstractions decide when learning updates are safe to apply.

Main entry points: [`metaclaw/memory/manager.py`](https://github.com/chris-han/metaclaw/blob/main/metaclaw/memory/manager.py) (Memory manager), [`metaclaw/api_server.py`](https://github.com/chris-han/metaclaw/blob/main/metaclaw/api_server.py) (API server), [`benchmark/src/run/run_cmd.py`](https://github.com/chris-han/metaclaw/blob/main/benchmark/src/run/run_cmd.py) (Run pipeline), [`metaclaw/launcher.py`](https://github.com/chris-han/metaclaw/blob/main/metaclaw/launcher.py) (Launcher)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core runtime"]
  node_cli["CLI<br/>entrypoint<br/>[cli.py]"]
  node_launcher["Launcher<br/>bootstrap<br/>[launcher.py]"]
  node_api_server["API server<br/>proxy server<br/>[api_server.py]"]
  node_setup_wizard["Setup wizard<br/>initializer<br/>[setup_wizard.py]"]
  node_config_store[("Config store<br/>state store<br/>[config_store.py]")]
  node_auth_store[("Auth store<br/>credentials store<br/>[auth_store.py]")]
  node_runtime_state[("Runtime state<br/>session state<br/>[runtime_state.py]")]
  node_scheduler["Scheduler<br/>async planner<br/>[scheduler.py]"]
  node_claw_adapter["Claw adapter<br/>compat adapter<br/>[claw_adapter.py]"]
  node_weaver_compat["Weaver compat<br/>compat layer<br/>[weaver_compat.py]"]
end

subgraph group_memory["Memory system"]
  node_skill_manager["Skill manager<br/>skill runtime<br/>[skill_manager.py]"]
  node_memory_manager["Memory manager<br/>memory runtime<br/>[manager.py]"]
  node_memory_store[("Memory store<br/>[store.py]")]
  node_memory_policy["Memory policy<br/>retrieval policy<br/>[policy.py]"]
  node_memory_sidecar["Sidecar service<br/>optional service<br/>[server.py]"]
end

subgraph group_learning["Learning loop"]
  node_trainer["Trainer<br/>rl control<br/>[trainer.py]"]
  node_prm_scorer["PRM scorer<br/>judge/scorer<br/>[prm_scorer.py]"]
  node_sdk_backend["SDK backend<br/>backend adapter<br/>[sdk_backend.py]"]
  node_rollout["Rollout<br/>data pipeline<br/>[rollout.py]"]
  node_openclaw_env_rollout["Env rollout<br/>integration pipeline"]
end

subgraph group_integration["Client integration"]
  node_openclaw_plugin["OpenClaw plugin<br/>ts integration<br/>[index.ts]"]
  node_extensions_openclaw["OpenClaw ext<br/>plugin package<br/>[index.ts]"]
end

subgraph group_benchmark["Benchmarking"]
  node_benchmark_cli["Benchmark CLI<br/>evaluation cli<br/>[cli.py]"]
  node_benchmark_checks["Checks<br/>validation suite<br/>[base.py]"]
  node_benchmark_run["Run pipeline<br/>eval pipeline<br/>[run_cmd.py]"]
  node_benchmark_data[("Bench data<br/>datasets")]
end

subgraph group_assets["Seed assets"]
  node_skills_seed["Skill seeds<br/>seed assets"]
  node_policy_seed["Policy seed<br/>seed assets<br/>[policy.json]"]
end

node_cli -->|"starts"| node_launcher
node_cli -->|"initializes"| node_setup_wizard
node_launcher -->|"serves"| node_api_server
node_launcher -->|"enables"| node_scheduler
node_api_server -->|"normalizes"| node_claw_adapter
node_api_server -->|"compatibility"| node_weaver_compat
node_api_server -->|"injects"| node_skill_manager
node_api_server -->|"recalls"| node_memory_manager
node_memory_manager -->|"persists"| node_memory_store
node_memory_manager -->|"governs"| node_memory_policy
node_memory_manager -.->|"delegates"| node_memory_sidecar
node_skill_manager -->|"seeds"| node_skills_seed
node_skill_manager -->|"learns from"| node_memory_manager
node_scheduler -->|"triggers"| node_trainer
node_trainer -->|"scores"| node_prm_scorer
node_trainer -->|"targets"| node_sdk_backend
node_rollout -->|"feeds"| node_trainer
node_rollout -->|"captures"| node_memory_manager
node_openclaw_env_rollout -->|"specializes"| node_rollout
node_extensions_openclaw -->|"packages"| node_openclaw_plugin
node_openclaw_plugin -->|"routes to"| node_api_server
node_benchmark_cli -->|"validates"| node_benchmark_checks
node_benchmark_cli -->|"orchestrates"| node_benchmark_run
node_benchmark_run -->|"uses"| node_benchmark_data
node_benchmark_run -.->|"exercises"| node_memory_manager
node_benchmark_run -.->|"exercises"| node_skill_manager
node_policy_seed -->|"bootstraps"| node_memory_manager
node_config_store -->|"configures"| node_launcher
node_auth_store -->|"authenticates"| node_api_server
node_runtime_state -->|"tracks"| node_scheduler

click node_cli "https://github.com/chris-han/metaclaw/blob/main/metaclaw/cli.py"
click node_launcher "https://github.com/chris-han/metaclaw/blob/main/metaclaw/launcher.py"
click node_api_server "https://github.com/chris-han/metaclaw/blob/main/metaclaw/api_server.py"
click node_setup_wizard "https://github.com/chris-han/metaclaw/blob/main/metaclaw/setup_wizard.py"
click node_config_store "https://github.com/chris-han/metaclaw/blob/main/metaclaw/config_store.py"
click node_auth_store "https://github.com/chris-han/metaclaw/blob/main/metaclaw/auth_store.py"
click node_runtime_state "https://github.com/chris-han/metaclaw/blob/main/metaclaw/runtime_state.py"
click node_scheduler "https://github.com/chris-han/metaclaw/blob/main/metaclaw/scheduler.py"
click node_claw_adapter "https://github.com/chris-han/metaclaw/blob/main/metaclaw/claw_adapter.py"
click node_weaver_compat "https://github.com/chris-han/metaclaw/blob/main/metaclaw/weaver_compat.py"
click node_skill_manager "https://github.com/chris-han/metaclaw/blob/main/metaclaw/skill_manager.py"
click node_memory_manager "https://github.com/chris-han/metaclaw/blob/main/metaclaw/memory/manager.py"
click node_memory_store "https://github.com/chris-han/metaclaw/blob/main/metaclaw/memory/store.py"
click node_memory_policy "https://github.com/chris-han/metaclaw/blob/main/metaclaw/memory/policy.py"
click node_memory_sidecar "https://github.com/chris-han/metaclaw/blob/main/openclaw-metaclaw-memory/sidecar/metaclaw_memory_sidecar/server.py"
click node_trainer "https://github.com/chris-han/metaclaw/blob/main/metaclaw/trainer.py"
click node_prm_scorer "https://github.com/chris-han/metaclaw/blob/main/metaclaw/prm_scorer.py"
click node_sdk_backend "https://github.com/chris-han/metaclaw/blob/main/metaclaw/sdk_backend.py"
click node_rollout "https://github.com/chris-han/metaclaw/blob/main/metaclaw/rollout.py"
click node_openclaw_env_rollout "https://github.com/chris-han/metaclaw/blob/main/metaclaw/openclaw_env_rollout.py"
click node_openclaw_plugin "https://github.com/chris-han/metaclaw/blob/main/openclaw-metaclaw-memory/src/index.ts"
click node_extensions_openclaw "https://github.com/chris-han/metaclaw/blob/main/extensions/metaclaw-openclaw/index.ts"
click node_benchmark_cli "https://github.com/chris-han/metaclaw/blob/main/benchmark/src/cli.py"
click node_benchmark_checks "https://github.com/chris-han/metaclaw/blob/main/benchmark/src/check/base.py"
click node_benchmark_run "https://github.com/chris-han/metaclaw/blob/main/benchmark/src/run/run_cmd.py"
click node_benchmark_data "https://github.com/chris-han/metaclaw/tree/main/benchmark/data/metaclaw-bench"
click node_skills_seed "https://github.com/chris-han/metaclaw/tree/main/memory_data/skills"
click node_policy_seed "https://github.com/chris-han/metaclaw/blob/main/memory_data/store/policy.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_launcher,node_api_server,node_setup_wizard,node_config_store,node_auth_store,node_runtime_state,node_scheduler,node_claw_adapter,node_weaver_compat toneBlue
class node_skill_manager,node_memory_manager,node_memory_store,node_memory_policy,node_memory_sidecar toneAmber
class node_trainer,node_prm_scorer,node_sdk_backend,node_rollout,node_openclaw_env_rollout toneMint
class node_openclaw_plugin,node_extensions_openclaw toneRose
class node_benchmark_cli,node_benchmark_checks,node_benchmark_run,node_benchmark_data toneIndigo
class node_skills_seed,node_policy_seed toneTeal
```

## Components

### Core runtime

Python MetaClaw control plane and serving path

- [CLI](https://github.com/chris-han/metaclaw/blob/main/metaclaw/cli.py): entrypoint · User-facing command surface for lifecycle, auth, config, and status · `metaclaw/cli.py`
- [Launcher](https://github.com/chris-han/metaclaw/blob/main/metaclaw/launcher.py): bootstrap · Starts the local proxy and wires startup modes · `metaclaw/launcher.py`
- [API server](https://github.com/chris-han/metaclaw/blob/main/metaclaw/api_server.py): proxy server · Serves incoming agent traffic and forwards requests upstream · `metaclaw/api_server.py`
- [Setup wizard](https://github.com/chris-han/metaclaw/blob/main/metaclaw/setup_wizard.py): initializer · Bootstraps local configuration and agent auto-setup · `metaclaw/setup_wizard.py`
- [Config store](https://github.com/chris-han/metaclaw/blob/main/metaclaw/config_store.py): state store · Persists local configuration and runtime settings · `metaclaw/config_store.py`
- [Auth store](https://github.com/chris-han/metaclaw/blob/main/metaclaw/auth_store.py): credentials store · Persists provider credentials and auth material · `metaclaw/auth_store.py`
- [Runtime state](https://github.com/chris-han/metaclaw/blob/main/metaclaw/runtime_state.py): session state · Tracks active sessions and control-plane runtime state · `metaclaw/runtime_state.py`
- [Scheduler](https://github.com/chris-han/metaclaw/blob/main/metaclaw/scheduler.py): async planner · Defers updates and learning work to low-interruption windows · `metaclaw/scheduler.py`
- [Claw adapter](https://github.com/chris-han/metaclaw/blob/main/metaclaw/claw_adapter.py): compat adapter · Normalizes request shapes for compatible agent/provider flows · `metaclaw/claw_adapter.py`
- [Weaver compat](https://github.com/chris-han/metaclaw/blob/main/metaclaw/weaver_compat.py): compat layer · Compatibility layer for alternate provider or request conventions · `metaclaw/weaver_compat.py`

### Memory system

In-process memory, skills, and optional sidecar

- [Skill manager](https://github.com/chris-han/metaclaw/blob/main/metaclaw/skill_manager.py): skill runtime · Loads, injects, and evolves Markdown skills at runtime · `metaclaw/skill_manager.py`
- [Memory manager](https://github.com/chris-han/metaclaw/blob/main/metaclaw/memory/manager.py): memory runtime · Coordinates retrieval, storage, consolidation, and policy · `metaclaw/memory/manager.py`
- [Memory store](https://github.com/chris-han/metaclaw/blob/main/metaclaw/memory/store.py): memory store · Local persistence for cross-session facts and episodic summaries · `metaclaw/memory/store.py`
- [Memory policy](https://github.com/chris-han/metaclaw/blob/main/metaclaw/memory/policy.py): retrieval policy · Controls recall, promotion, and scope behavior · `metaclaw/memory/policy.py`
- [Sidecar service](https://github.com/chris-han/metaclaw/blob/main/openclaw-metaclaw-memory/sidecar/metaclaw_memory_sidecar/server.py): optional service · Optional isolated HTTP memory service for reads and writes · `openclaw-metaclaw-memory/sidecar/metaclaw_memory_sidecar/server.py`

### Learning loop

RL, rollout, scoring, and backend orchestration

- [Trainer](https://github.com/chris-han/metaclaw/blob/main/metaclaw/trainer.py): rl control · Packages samples and coordinates backend fine-tuning · `metaclaw/trainer.py`
- [PRM scorer](https://github.com/chris-han/metaclaw/blob/main/metaclaw/prm_scorer.py): judge/scorer · Asynchronously scores turns before training or consolidation · `metaclaw/prm_scorer.py`
- [SDK backend](https://github.com/chris-han/metaclaw/blob/main/metaclaw/sdk_backend.py): backend adapter · Abstracts training backends such as Tinker, MinT, and Weaver · `metaclaw/sdk_backend.py`
- [Rollout](https://github.com/chris-han/metaclaw/blob/main/metaclaw/rollout.py): data pipeline · Converts live conversations into training and replay artifacts · `metaclaw/rollout.py`
- [Env rollout](https://github.com/chris-han/metaclaw/blob/main/metaclaw/openclaw_env_rollout.py): integration pipeline · Runs rollout against OpenClaw-style agent environments · `metaclaw/openclaw_env_rollout.py`

### Client integration

OpenClaw plugin and external agent boundary

- [OpenClaw plugin](https://github.com/chris-han/metaclaw/blob/main/openclaw-metaclaw-memory/src/index.ts): ts integration · Client-side plugin package that connects OpenClaw to MetaClaw memory · `openclaw-metaclaw-memory/src/index.ts`
- [OpenClaw ext](https://github.com/chris-han/metaclaw/blob/main/extensions/metaclaw-openclaw/index.ts): plugin package · Lightweight OpenClaw integration package · `extensions/metaclaw-openclaw/index.ts`

### Benchmarking

Separate evaluation and reporting stack

- [Benchmark CLI](https://github.com/chris-han/metaclaw/blob/main/benchmark/src/cli.py): evaluation cli · Entry point for benchmark execution, inference, scoring, and reporting · `benchmark/src/cli.py`
- [Checks](https://github.com/chris-han/metaclaw/blob/main/benchmark/src/check/base.py): validation suite · Integrity and structure validators for benchmark data · `benchmark/src/check/base.py`
- [Run pipeline](https://github.com/chris-han/metaclaw/blob/main/benchmark/src/run/run_cmd.py): eval pipeline · Benchmark run, infer, scoring, and report stages · `benchmark/src/run/run_cmd.py`
- [Bench data](https://github.com/chris-han/metaclaw/tree/main/benchmark/data/metaclaw-bench): datasets · Packaged tasks, sessions, and workspace snapshots for evaluation · `benchmark/data/metaclaw-bench`

### Seed assets

Bundled skill and policy data used at runtime and evaluation

- [Skill seeds](https://github.com/chris-han/metaclaw/tree/main/memory_data/skills): seed assets · Bundled skill markdown used to seed the runtime skill library · `memory_data/skills`
- [Policy seed](https://github.com/chris-han/metaclaw/blob/main/memory_data/store/policy.json): seed assets · Bundled policy data used to bootstrap memory behavior · `memory_data/store/policy.json`

## Connections

- CLI → Launcher: starts · CLI drives local runtime startup
- CLI → Setup wizard: initializes · CLI can bootstrap configuration and agent setup
- Launcher → API server: serves · Launcher brings up the local proxy/server
- Launcher → Scheduler: enables · Auto mode wires background scheduling
- API server → Claw adapter: normalizes · Proxy adapts inbound agent requests
- API server → Weaver compat: compatibility · Proxy supports alternate request/provider compatibility
- API server → Skill manager: injects · Serving path enriches prompts with skills
- API server → Memory manager: recalls · Serving path can attach long-term memory
- Memory manager → Memory store: persists · Memory writes and retrieval state are stored locally
- Memory manager → Memory policy: governs · Policy controls recall and promotion decisions
- Memory manager → Sidecar service: delegates · Optional sidecar can isolate memory operations
- Skill manager → Skill seeds: seeds · Runtime skill library is bootstrapped from bundled assets
- Skill manager → Memory manager: learns from · Post-session summaries can promote new skills
- Scheduler → Trainer: triggers · Scheduler decides when consolidation and updates run
- Trainer → PRM scorer: scores · Training pipeline uses asynchronous judge scoring
- Trainer → SDK backend: targets · Backend abstraction routes to supported training services
- Rollout → Trainer: feeds · Conversation rollouts become training samples
- Rollout → Memory manager: captures · Rollout captures memory-relevant conversation artifacts
- Env rollout → Rollout: specializes · Environment rollout is a concrete rollout mode
- OpenClaw ext → OpenClaw plugin: packages · Repository includes a lightweight OpenClaw integration package
- OpenClaw plugin → API server: routes to · Client plugin sends traffic through MetaClaw
- Benchmark CLI → Checks: validates · Benchmark stack checks data integrity and structure
- Benchmark CLI → Run pipeline: orchestrates · CLI drives benchmark run and scoring stages
- Run pipeline → Bench data: uses · Evaluation pipeline consumes packaged datasets and sessions
- Run pipeline → Memory manager: exercises · Benchmarks stress the same memory assumptions as runtime
- Run pipeline → Skill manager: exercises · Benchmarks also evaluate skill retrieval and injection behavior
- Policy seed → Memory manager: bootstraps · Seed policy informs local memory behavior at startup
- Config store → Launcher: configures · Launcher reads persisted runtime configuration
- Auth store → API server: authenticates · Provider credentials are consumed by the serving path
- Runtime state → Scheduler: tracks · State store supports scheduling and session coordination
