# windcherry/mini-openclaw architecture

> Architecture diagram of the GitHub repository windcherry/mini-openclaw, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/windcherry/mini-openclaw
- Repository: https://github.com/windcherry/mini-openclaw

## Overview

1. **Overall shape**
   - This repo is a Python command-line agent skeleton.
   - The core architecture is a **loop-based agent** that sends state to an **LLM backend**, receives **tool calls**, executes tools locally or via plugins, then feeds results back until the task is done.

2. **Entry point and orchestration**
   - `agent/cli.py` is the user-facing entry point for running the agent from the terminal.
   - `agent/loop.py` is the central controller: it owns the turn-by-turn reasoning/execution cycle.
   - `agent/context.py` likely holds the conversation/task state that is accumulated and passed through the loop.

3. **Model/backend boundary**
   - `backend/` is the abstraction for talking to the model provider.
   - `backend/client.py` is the real API client path; the README says it is set up for a DeepSeek-style backend.
   - `backend/server.py` and `backend/fake_backend.py` suggest two modes: a real serving layer and a local/mock backend for self-checks or development without external API calls.
   - This boundary separates “agent logic” from “how the model is reached.”

4. **Prompt rendering and tool-call parsing**
   - `prompt/render.py` is the formatting layer that turns agent state, messages, and available tools into the model prompt.
   - This layer is important because the model must be told both the current task context and the tool schema.
   - The repo README implies there is also parsing of model output into structured tool calls, so prompt handling is a dedicated subsystem rather than embedded in the loop.

5. **Local tool execution layer**
   - `tools/` contains the built-in actions the agent can invoke.
   - `tools/base.py` is the common interface/contract for tools.
   - `tools/fs.py`, `tools/shell.py`, and `tools/more_tools.py` indicate a split between filesystem operations, shell/command execution, and additional utility tools.
   - Architecturally, this is the “actuator” layer: it takes structured tool requests and performs side effects on the local machine.

6. **MCP integration boundary**
   - `mcp/` is a separate subsystem for connecting to external tool servers using the Model Context Protocol.
   - `mcp/client.py` and `mcp/echo_server.py` imply a client that can talk to third-party or local MCP servers, plus a minimal test/demo server.
   - In the architecture, MCP tools sit alongside built-in tools, but they are sourced from external processes rather than from the repo’s own Python tool modules.

7. **Skills as domain plugins**
   - `skills/` is a plugin-like content layer for reusable domain knowledge or task procedures.
   - `skills/example-skill/SKILL.md` shows that skills are file-based and markdown-described, not code-heavy.
   - `skills/loader.py` is the discovery/loading mechanism, so skills can be injected into the agent without changing the core loop.
   - This gives the agent extensibility at the knowledge/workflow level, distinct from tools.

8. **Evaluation subsystem**
   - `eval/tasks.py` and `eval/metrics.py` form a standalone evaluation harness.
   - This subsystem is used to measure agent behavior against task sets and compute metrics, likely supporting the repo’s day-by-day milestone validation.
   - It is logically separate from runtime execution: it judges the agent rather than participating in normal tasks.

9. **Data flow through a single task**
   - User request enters `agent.cli`.
   - `agent.loop` builds context, renders prompts, and sends them to `backend`.
   - The backend returns either a final answer or a structured tool request.
   - Tool requests are dispatched to built-in `tools/`, MCP tools, or skill-backed behavior.
   - Results are appended to context and sent back through the loop until completion.

10. **Control and safety implications**
   - The README explicitly frames the project as having a future “security layer” for permissions, sandboxing, and prompt-injection defense.
   - Even if not fully implemented yet, the architecture already anticipates a boundary between the model’s requests and the actual side effects performed by tools.
   - That means tool dispatch is the natural enforcement point for safety checks.

11. **Development/runtime characteristics**
   - Everything is Python-based, with the README recommending Python 3.11.
   - The agent side is lightweight and command-line driven; there is no obvious web frontend in this repo.
   - External dependencies are mainly the model API client and any MCP servers the agent connects to.

12. **How to draw the diagram**
   - Draw one central loop box for `agent/loop.py`.
   - Connect it upward to `backend/` for model inference.
   - Connect it downward to a tool dispatcher that fans out to `tools/`, `mcp/`, and `skills/`.
   - Add `prompt/` and `agent/context.py` as supporting layers feeding the loop.
   - Put `eval/` off to the side as a validation harness rather than part of the runtime path.

Main entry points: [`agent/loop.py`](https://github.com/windcherry/mini-openclaw/blob/main/agent/loop.py) (Loop), [`tools/base.py`](https://github.com/windcherry/mini-openclaw/blob/main/tools/base.py) (Tool base), [`prompt/render.py`](https://github.com/windcherry/mini-openclaw/blob/main/prompt/render.py) (Render), [`eval/tasks.py`](https://github.com/windcherry/mini-openclaw/blob/main/eval/tasks.py) (Tasks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_agent["Agent runtime"]
  node_agent_cli["CLI<br/>entrypoint<br/>[cli.py]"]
  node_agent_loop(("Loop<br/>orchestrator<br/>[loop.py]"))
  node_agent_context["Context<br/>state<br/>[context.py]"]
  node_agent_prompts["Agent prompts<br/>prompt defs<br/>[prompts.py]"]
end

subgraph group_grp_model["Model backend"]
  node_backend_client["Client<br/>[client.py]"]
  node_backend_server["Server<br/>[server.py]"]
  node_backend_fake["Fake backend<br/>mock backend<br/>[fake_backend.py]"]
end

subgraph group_grp_io["Prompting"]
  node_prompt_render["Render<br/>prompt builder<br/>[render.py]"]
end

subgraph group_grp_tools["Execution tools"]
  node_tools_base["Tool base<br/>tool contract<br/>[base.py]"]
  node_tools_fs["Filesystem<br/>local tool<br/>[fs.py]"]
  node_tools_shell["Shell<br/>local tool<br/>[shell.py]"]
  node_tools_more["Extra tools<br/>local tools<br/>[more_tools.py]"]
  node_mcp_client["MCP client<br/>tool bridge<br/>[client.py]"]
  node_mcp_echo["Echo server<br/>mcp demo<br/>[echo_server.py]"]
end

subgraph group_grp_skills["Skills"]
  node_skills_loader["Skill loader<br/>[loader.py]"]
  node_skill_example["Example skill<br/>skill content<br/>[SKILL.md]"]
end

subgraph group_grp_eval["Evaluation"]
  node_eval_tasks["Tasks<br/>eval suite<br/>[tasks.py]"]
  node_eval_metrics["Metrics<br/>eval scoring<br/>[metrics.py]"]
end

node_agent_cli -->|"starts"| node_agent_loop
node_agent_loop -->|"reads/writes"| node_agent_context
node_agent_loop -->|"uses"| node_agent_prompts
node_agent_loop -->|"renders"| node_prompt_render
node_prompt_render -->|"consumes"| node_agent_context
node_prompt_render -->|"describes"| node_tools_base
node_agent_loop -->|"queries"| node_backend_client
node_agent_loop -.->|"can swap"| node_backend_fake
node_backend_client -.->|"served by"| node_backend_server
node_agent_loop -->|"dispatches"| node_tools_fs
node_agent_loop -->|"dispatches"| node_tools_shell
node_agent_loop -->|"dispatches"| node_tools_more
node_tools_base -.->|"implements"| node_tools_fs
node_tools_base -.->|"implements"| node_tools_shell
node_tools_base -.->|"implements"| node_tools_more
node_agent_loop -->|"delegates"| node_mcp_client
node_mcp_client -.->|"connects"| node_mcp_echo
node_skills_loader -->|"loads"| node_skill_example
node_agent_loop -->|"injects"| node_skills_loader
node_eval_tasks -->|"scores with"| node_eval_metrics
node_eval_tasks -.->|"exercises"| node_agent_loop

click node_agent_cli "https://github.com/windcherry/mini-openclaw/blob/main/agent/cli.py"
click node_agent_loop "https://github.com/windcherry/mini-openclaw/blob/main/agent/loop.py"
click node_agent_context "https://github.com/windcherry/mini-openclaw/blob/main/agent/context.py"
click node_agent_prompts "https://github.com/windcherry/mini-openclaw/blob/main/agent/prompts.py"
click node_prompt_render "https://github.com/windcherry/mini-openclaw/blob/main/prompt/render.py"
click node_backend_client "https://github.com/windcherry/mini-openclaw/blob/main/backend/client.py"
click node_backend_server "https://github.com/windcherry/mini-openclaw/blob/main/backend/server.py"
click node_backend_fake "https://github.com/windcherry/mini-openclaw/blob/main/backend/fake_backend.py"
click node_tools_base "https://github.com/windcherry/mini-openclaw/blob/main/tools/base.py"
click node_tools_fs "https://github.com/windcherry/mini-openclaw/blob/main/tools/fs.py"
click node_tools_shell "https://github.com/windcherry/mini-openclaw/blob/main/tools/shell.py"
click node_tools_more "https://github.com/windcherry/mini-openclaw/blob/main/tools/more_tools.py"
click node_mcp_client "https://github.com/windcherry/mini-openclaw/blob/main/mcp/client.py"
click node_mcp_echo "https://github.com/windcherry/mini-openclaw/blob/main/mcp/echo_server.py"
click node_skills_loader "https://github.com/windcherry/mini-openclaw/blob/main/skills/loader.py"
click node_skill_example "https://github.com/windcherry/mini-openclaw/blob/main/skills/example-skill/SKILL.md"
click node_eval_tasks "https://github.com/windcherry/mini-openclaw/blob/main/eval/tasks.py"
click node_eval_metrics "https://github.com/windcherry/mini-openclaw/blob/main/eval/metrics.py"

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_agent_cli,node_agent_loop,node_agent_context,node_agent_prompts toneBlue
class node_backend_client,node_backend_server,node_backend_fake toneAmber
class node_prompt_render toneMint
class node_tools_base,node_tools_fs,node_tools_shell,node_tools_more,node_mcp_client,node_mcp_echo toneRose
class node_skills_loader,node_skill_example toneIndigo
class node_eval_tasks,node_eval_metrics toneTeal
```

## Components

### Agent runtime

CLI entrypoint, loop, and shared task state.

- [CLI](https://github.com/windcherry/mini-openclaw/blob/main/agent/cli.py): entrypoint · Terminal entrypoint for running the agent. · `agent/cli.py`
- [Loop](https://github.com/windcherry/mini-openclaw/blob/main/agent/loop.py): orchestrator · Main turn-by-turn controller for reasoning and execution. · `agent/loop.py`
- [Context](https://github.com/windcherry/mini-openclaw/blob/main/agent/context.py): state · Conversation and task state carried through the loop. · `agent/context.py`
- [Agent prompts](https://github.com/windcherry/mini-openclaw/blob/main/agent/prompts.py): prompt defs · Agent-facing prompt templates and prompt constants. · `agent/prompts.py`

### Model backend

Interfaces for reaching the LLM and local backend modes.

- [Client](https://github.com/windcherry/mini-openclaw/blob/main/backend/client.py): llm client · Primary API client for the model provider. · `backend/client.py`
- [Server](https://github.com/windcherry/mini-openclaw/blob/main/backend/server.py): backend server · Serving-side backend entry for model access or local hosting. · `backend/server.py`
- [Fake backend](https://github.com/windcherry/mini-openclaw/blob/main/backend/fake_backend.py): mock backend · Local mock backend for development and self-checks. · `backend/fake_backend.py`

### Prompting

Prompt rendering and message/schema preparation.

- [Render](https://github.com/windcherry/mini-openclaw/blob/main/prompt/render.py): prompt builder · Formats state, messages, and tool schemas into model input. · `prompt/render.py`

### Execution tools

Built-in local tools and external tool integration.

- [Tool base](https://github.com/windcherry/mini-openclaw/blob/main/tools/base.py): tool contract · Shared interface and contract for executable tools. · `tools/base.py`
- [Filesystem](https://github.com/windcherry/mini-openclaw/blob/main/tools/fs.py): local tool · File and path operations exposed to the agent. · `tools/fs.py`
- [Shell](https://github.com/windcherry/mini-openclaw/blob/main/tools/shell.py): local tool · Command execution and shell-based actions. · `tools/shell.py`
- [Extra tools](https://github.com/windcherry/mini-openclaw/blob/main/tools/more_tools.py): local tools · Additional built-in utility tools. · `tools/more_tools.py`
- [MCP client](https://github.com/windcherry/mini-openclaw/blob/main/mcp/client.py): tool bridge · Connects the agent to external MCP tool servers. · `mcp/client.py`
- [Echo server](https://github.com/windcherry/mini-openclaw/blob/main/mcp/echo_server.py): mcp demo · Minimal local MCP server for testing and examples. · `mcp/echo_server.py`

### Skills

File-based reusable task knowledge and loaders.

- [Skill loader](https://github.com/windcherry/mini-openclaw/blob/main/skills/loader.py): skill loader · Discovers and loads file-based skills into the agent. · `skills/loader.py`
- [Example skill](https://github.com/windcherry/mini-openclaw/blob/main/skills/example-skill/SKILL.md): skill content · Markdown skill example showing the file-based skill format. · `skills/example-skill/SKILL.md`

### Evaluation

Task harness and metrics for measuring behavior.

- [Tasks](https://github.com/windcherry/mini-openclaw/blob/main/eval/tasks.py): eval suite · Task definitions used for evaluation runs. · `eval/tasks.py`
- [Metrics](https://github.com/windcherry/mini-openclaw/blob/main/eval/metrics.py): eval scoring · Scoring and measurement logic for agent evaluation. · `eval/metrics.py`

## Connections

- CLI → Loop: starts · CLI launches the main agent loop.
- Loop → Context: reads/writes · Loop maintains and updates task state.
- Loop → Agent prompts: uses · Loop relies on agent prompt templates.
- Loop → Render: renders · Loop asks the prompt layer to build model input.
- Render → Context: consumes · Prompt rendering uses accumulated context.
- Render → Tool base: describes · Prompt rendering includes available tool schema.
- Loop → Client: queries · Loop sends prompts to the primary model client.
- Loop → Fake backend: can swap · Development mode can use the fake backend.
- Client → Server: served by · Client path can target a server-side backend.
- Loop → Filesystem: dispatches · Structured tool calls can perform filesystem actions.
- Loop → Shell: dispatches · Structured tool calls can execute shell actions.
- Loop → Extra tools: dispatches · Loop can invoke additional built-in tools.
- Tool base → Filesystem: implements · Filesystem tool follows the shared tool contract.
- Tool base → Shell: implements · Shell tool follows the shared tool contract.
- Tool base → Extra tools: implements · Extra tools follow the shared tool contract.
- Loop → MCP client: delegates · Loop can route tool requests to MCP servers.
- MCP client → Echo server: connects · Client can talk to local or external MCP servers.
- Skill loader → Example skill: loads · Loader discovers markdown skill content.
- Loop → Skill loader: injects · Loaded skills augment the agent's behavior.
- Tasks → Metrics: scores with · Evaluation tasks are measured using metrics.
- Tasks → Loop: exercises · Evaluation harness drives the runtime loop.
