# saferl-lab/cheetahclaws architecture

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

- Interactive diagram: https://gitdiagram.com/saferl-lab/cheetahclaws
- Repository: https://github.com/saferl-lab/cheetahclaws

## Overview

1. **What this repo is**
   CheetahClaws is a Python-native AI assistant platform centered on a model-agnostic agent loop. It can run as an interactive terminal REPL, a browser-based web app, or a bridge-connected assistant inside Slack/Telegram/WeChat. The core architecture is “prompt in → agent loop → tools/providers/state → streamed events out.”

2. **Top-level runtime entry points**
   The main execution paths appear to be `cheetahclaws.py`, `agent.py`, and `agent_runner.py`, with supporting bootstrap/runtime modules. These coordinate startup, config loading, model selection, REPL/web mode, and dispatch into the agent execution loop.

3. **Core orchestration layer**
   The central abstraction is the agent loop that streams typed events such as text chunks and tool lifecycle events. This layer sits between the user-facing interface and all execution capabilities. It is responsible for deciding when to call the model, when to invoke tools, when to ask the user for approval, and when a turn is complete.

4. **Model/provider boundary**
   `providers.py` and `cc_config.py` define the model abstraction and provider selection. The system is designed to work with Anthropic, OpenAI-compatible endpoints, Gemini, local Ollama-style models, and custom backends. This boundary matters because tool calling, streaming, and thinking/output formats vary by provider.

5. **Context assembly and conversation control**
   `context.py`, `compaction.py`, and `session_store.py` manage what gets sent to the model on each turn. The assistant injects session history, current working directory state, git status, persistent memory, and project instructions, then compacts older context when needed. This is the main data reduction boundary before requests reach the model.

6. **Tool execution plane**
   `tool_registry.py` plus `tools/` form the generic tool bus. Built-in tools cover filesystem work, shell execution, web access, diagnostics, notebook editing, browser/email utilities, and interaction helpers. Tools are registered into the same interface as plugin and MCP-provided tools, so the agent treats them uniformly at execution time.

7. **Skills, commands, and mode switches**
   The `commands/` and `skill/` packages implement the user command surface and reusable markdown-based skills. Commands like plan mode, checkpoint, memory, agent spawning, and bridge setup are not just UI sugar—they alter agent permissions, tool availability, and workflow state. This layer is where “assistant modes” are enforced.

8. **Persistence and long-term state**
   Several subsystems persist distinct kinds of state: `checkpoint/` snapshots conversation plus file state for rewind; `memory/` stores user/project memories with consolidation and search; `task/` stores dependency-aware task graphs; `jobs.py` tracks remote bridge job queues. The architecture keeps these stores separate, which helps explain why a single turn can affect history, memory, tasks, and checkpoints independently.

9. **Multi-agent and background automation**
   `subagent.py`, `multi_agent/`, and `modular/` support delegated execution patterns. The repo includes autonomous subagents, brainstorming, worker pipelines, and proactive/background loops. These are layered on top of the same core agent/tool stack, but operate as separate agents or scheduled jobs rather than direct chat turns.

10. **Frontends: terminal and web**
   `ui/` supports the terminal REPL experience, while `web/` implements a browser UI with chat streaming, auth, sessions, and a PTY terminal view. The web stack persists session data to SQLite, serves static JS modules, and exposes `/api/*`, `/health`, and `/metrics` endpoints. This is a distinct presentation boundary from the CLI, but both ultimately drive the same agent backend.

11. **Messaging bridges**
   `bridges/` connects the assistant to Slack, Telegram, WeChat, and an interactive session adapter. These adapters translate external messages into agent turns and return responses back to the originating channel. They also introduce queueing and remote job handling when the agent is busy.

12. **Domain-specific modules**
   `modular/trading`, `modular/video`, and `modular/voice` are specialized subsystems built on the same platform. Trading adds data fetchers, indicators, multi-agent analysis, and backtesting engines; video and voice add media pipelines for narration, transcription, and content generation. These are not separate apps so much as vertical workflows plugged into the assistant core.

13. **MCP and extensibility**
   `cc_mcp/` provides MCP client/config/tool integration, and `plugin/` enables loading and managing external plugins. The repo’s extension model is intentionally dynamic: MCP servers, git-based plugins, and runtime tool registration all expand the tool surface without rebuilding the project.

14. **Operational concerns and safeguards**
   `circuit_breaker.py`, `quota.py`, `health.py`, `error_classifier.py`, and logging utilities handle reliability, limits, and observability. The web layer also adds structured logs and metrics. Architecturally, these are guardrails around the agent loop rather than part of the reasoning path itself.

Main entry points: [`agent.py`](https://github.com/saferl-lab/cheetahclaws/blob/main/agent.py) (Agent Loop), [`tool_registry.py`](https://github.com/saferl-lab/cheetahclaws/blob/main/tool_registry.py) (Tool Registry), [`context.py`](https://github.com/saferl-lab/cheetahclaws/blob/main/context.py) (Context), [`agent_runner.py`](https://github.com/saferl-lab/cheetahclaws/blob/main/agent_runner.py) (Runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime Core"]
  node_cheetahclaws_py["Main CLI<br/>entrypoint<br/>[cheetahclaws.py]"]
  node_agent_py(("Agent Loop<br/>orchestrator<br/>[agent.py]"))
  node_agent_runner_py["Runner<br/>runtime<br/>[agent_runner.py]"]
  node_bootstrap_py["Bootstrap<br/>startup<br/>[bootstrap.py]"]
  node_providers_py["Providers<br/>model boundary<br/>[providers.py]"]
  node_cc_config_py["Config<br/>[cc_config.py]"]
  node_subagent_py(("Subagents<br/>delegation<br/>[subagent.py]"))
  node_multi_agent_pkg["Multi-Agent<br/>coordination<br/>[subagent.py]"]
  node_monitor_pkg["Monitor<br/>background jobs<br/>[scheduler.py]"]
end

subgraph group_interface["Interfaces"]
  node_ui_pkg["Terminal UI<br/>cli frontend<br/>[input.py]"]
  node_web_pkg["Web App<br/>web frontend<br/>[server.py]"]
  node_bridges_pkg["Bridges<br/>messaging adapters<br/>[slack.py]"]
  node_commands_pkg["Commands<br/>[core.py]"]
end

subgraph group_state["State & Context"]
  node_context_py["Context<br/>prompt assembly<br/>[context.py]"]
  node_compaction_py["Compaction<br/>context reduction<br/>[compaction.py]"]
  node_session_store_py[("Session Store<br/>state store<br/>[session_store.py]")]
  node_memory_pkg[("Memory<br/>long-term state<br/>[memory.py]")]
  node_checkpoint_pkg[("Checkpointing<br/>snapshot store<br/>[store.py]")]
  node_task_pkg[("Tasks<br/>task graph<br/>[store.py]")]
end

subgraph group_ext["Extensibility"]
  node_tool_registry_py["Tool Registry<br/>tool bus<br/>[tool_registry.py]"]
  node_tools_pkg["Core Tools<br/>built-in tools<br/>[fs.py]"]
  node_skill_pkg["Skills<br/>[executor.py]"]
  node_plugin_pkg["Plugins<br/>extension loading<br/>[loader.py]"]
  node_cc_mcp_pkg["MCP Bridge<br/>mcp integration<br/>[client.py]"]
end

subgraph group_domain["Domain Modules"]
  node_modular_pkg["Vertical Apps<br/>domain platform<br/>[base.py]"]
end

subgraph group_ops["Ops & Safety"]
  node_health_py["Health<br/>ops<br/>[health.py]"]
  node_quota_py["Quota<br/>guardrail<br/>[quota.py]"]
  node_circuit_breaker_py["Circuit Breaker<br/>reliability<br/>[circuit_breaker.py]"]
  node_error_classifier_py["Error Classifier<br/>diagnostics"]
  node_logging_utils_py["Logging<br/>observability<br/>[logging_utils.py]"]
end

node_cheetahclaws_py -->|"boot"| node_bootstrap_py
node_cheetahclaws_py -->|"launch"| node_agent_py
node_agent_runner_py -->|"runs"| node_agent_py
node_agent_py -->|"calls model"| node_providers_py
node_providers_py -->|"selects backend"| node_cc_config_py
node_agent_py -->|"builds prompt"| node_context_py
node_context_py -->|"reduces"| node_compaction_py
node_context_py -->|"loads state"| node_session_store_py
node_context_py -->|"injects memory"| node_memory_pkg
node_context_py -->|"reads snapshots"| node_checkpoint_pkg
node_agent_py -->|"uses tools"| node_tool_registry_py
node_tool_registry_py -->|"routes core tools"| node_tools_pkg
node_tool_registry_py -->|"enables skills"| node_skill_pkg
node_tool_registry_py -->|"loads plugins"| node_plugin_pkg
node_tool_registry_py -->|"bridges mcp"| node_cc_mcp_pkg
node_commands_pkg -->|"switches modes"| node_skill_pkg
node_commands_pkg -->|"manages"| node_checkpoint_pkg
node_commands_pkg -->|"manages"| node_memory_pkg
node_ui_pkg -->|"drives"| node_agent_runner_py
node_web_pkg -->|"drives"| node_agent_runner_py
node_bridges_pkg -->|"routes messages"| node_agent_runner_py
node_subagent_py -->|"delegates to"| node_agent_py
node_multi_agent_pkg -->|"coordinates"| node_subagent_py
node_monitor_pkg -->|"schedules"| node_agent_runner_py
node_modular_pkg -->|"extends"| node_tool_registry_py
node_modular_pkg -->|"uses skills"| node_skill_pkg
node_agent_py -->|"checks limits"| node_quota_py
node_agent_py -->|"guards"| node_circuit_breaker_py
node_agent_py -->|"classifies errors"| node_error_classifier_py
node_web_pkg -->|"logs"| node_logging_utils_py
node_agent_py -->|"reports health"| node_health_py

click node_cheetahclaws_py "https://github.com/saferl-lab/cheetahclaws/blob/main/cheetahclaws.py"
click node_agent_py "https://github.com/saferl-lab/cheetahclaws/blob/main/agent.py"
click node_agent_runner_py "https://github.com/saferl-lab/cheetahclaws/blob/main/agent_runner.py"
click node_bootstrap_py "https://github.com/saferl-lab/cheetahclaws/blob/main/bootstrap.py"
click node_providers_py "https://github.com/saferl-lab/cheetahclaws/blob/main/providers.py"
click node_cc_config_py "https://github.com/saferl-lab/cheetahclaws/blob/main/cc_config.py"
click node_context_py "https://github.com/saferl-lab/cheetahclaws/blob/main/context.py"
click node_compaction_py "https://github.com/saferl-lab/cheetahclaws/blob/main/compaction.py"
click node_session_store_py "https://github.com/saferl-lab/cheetahclaws/blob/main/session_store.py"
click node_memory_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/memory.py"
click node_checkpoint_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/checkpoint/store.py"
click node_task_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/task/store.py"
click node_tool_registry_py "https://github.com/saferl-lab/cheetahclaws/blob/main/tool_registry.py"
click node_tools_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/tools/fs.py"
click node_skill_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/skill/executor.py"
click node_plugin_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/plugin/loader.py"
click node_cc_mcp_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/cc_mcp/client.py"
click node_ui_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/ui/input.py"
click node_web_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/web/server.py"
click node_bridges_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/bridges/slack.py"
click node_commands_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/commands/core.py"
click node_subagent_py "https://github.com/saferl-lab/cheetahclaws/blob/main/subagent.py"
click node_multi_agent_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/multi_agent/subagent.py"
click node_modular_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/modular/base.py"
click node_monitor_pkg "https://github.com/saferl-lab/cheetahclaws/blob/main/monitor/scheduler.py"
click node_health_py "https://github.com/saferl-lab/cheetahclaws/blob/main/health.py"
click node_quota_py "https://github.com/saferl-lab/cheetahclaws/blob/main/quota.py"
click node_circuit_breaker_py "https://github.com/saferl-lab/cheetahclaws/blob/main/circuit_breaker.py"
click node_error_classifier_py "https://github.com/saferl-lab/cheetahclaws/blob/main/error_classifier.py"
click node_logging_utils_py "https://github.com/saferl-lab/cheetahclaws/blob/main/logging_utils.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_cheetahclaws_py,node_agent_py,node_agent_runner_py,node_bootstrap_py,node_providers_py,node_cc_config_py,node_subagent_py,node_multi_agent_pkg,node_monitor_pkg toneBlue
class node_ui_pkg,node_web_pkg,node_bridges_pkg,node_commands_pkg toneAmber
class node_context_py,node_compaction_py,node_session_store_py,node_memory_pkg,node_checkpoint_pkg,node_task_pkg toneMint
class node_tool_registry_py,node_tools_pkg,node_skill_pkg,node_plugin_pkg,node_cc_mcp_pkg toneRose
class node_modular_pkg toneIndigo
class node_health_py,node_quota_py,node_circuit_breaker_py,node_error_classifier_py,node_logging_utils_py toneTeal
```

## Components

### Runtime Core

Startup, orchestration, and execution loop.

- [Main CLI](https://github.com/saferl-lab/cheetahclaws/blob/main/cheetahclaws.py): entrypoint · Primary process bootstrap and mode selection. · `cheetahclaws.py`
- [Agent Loop](https://github.com/saferl-lab/cheetahclaws/blob/main/agent.py): orchestrator · Core turn loop coordinating model calls, tools, and streamed events. · `agent.py`
- [Runner](https://github.com/saferl-lab/cheetahclaws/blob/main/agent_runner.py): runtime · Execution harness for agent sessions and background runs. · `agent_runner.py`
- [Bootstrap](https://github.com/saferl-lab/cheetahclaws/blob/main/bootstrap.py): startup · Startup wiring and environment initialization. · `bootstrap.py`
- [Providers](https://github.com/saferl-lab/cheetahclaws/blob/main/providers.py): model boundary · Model backends and provider-specific behavior. · `providers.py`
- [Config](https://github.com/saferl-lab/cheetahclaws/blob/main/cc_config.py): configuration · Runtime configuration and provider selection. · `cc_config.py`
- [Subagents](https://github.com/saferl-lab/cheetahclaws/blob/main/subagent.py): delegation · Delegated agent execution and handoff patterns. · `subagent.py`
- [Multi-Agent](https://github.com/saferl-lab/cheetahclaws/blob/main/multi_agent/subagent.py): coordination · Brainstorming and worker pipeline coordination. · `multi_agent/subagent.py`
- [Monitor](https://github.com/saferl-lab/cheetahclaws/blob/main/monitor/scheduler.py): background jobs · Scheduling, notifications, summarization, and fetchers. · `monitor/scheduler.py`

### Interfaces

User-facing entry points and message bridges.

- [Terminal UI](https://github.com/saferl-lab/cheetahclaws/blob/main/ui/input.py): cli frontend · REPL input and terminal rendering. · `ui/input.py`
- [Web App](https://github.com/saferl-lab/cheetahclaws/blob/main/web/server.py): web frontend · Browser chat UI, auth, API, and session-backed server. · `web/server.py`
- [Bridges](https://github.com/saferl-lab/cheetahclaws/blob/main/bridges/slack.py): messaging adapters · Slack, Telegram, WeChat, and interactive session adapters. · `bridges/slack.py`
- [Commands](https://github.com/saferl-lab/cheetahclaws/blob/main/commands/core.py): mode commands · Command surface for plan, checkpoint, memory, agent, and config actions. · `commands/core.py`

### State & Context

Conversation context, persistence, and task state.

- [Context](https://github.com/saferl-lab/cheetahclaws/blob/main/context.py): prompt assembly · Builds turn context from state, workspace, and instructions. · `context.py`
- [Compaction](https://github.com/saferl-lab/cheetahclaws/blob/main/compaction.py): context reduction · Shrinks older context before model requests. · `compaction.py`
- [Session Store](https://github.com/saferl-lab/cheetahclaws/blob/main/session_store.py): state store · Persists session-level conversation and runtime state. · `session_store.py`
- [Memory](https://github.com/saferl-lab/cheetahclaws/blob/main/memory.py): long-term state · User and project memory management. · `memory.py`
- [Checkpointing](https://github.com/saferl-lab/cheetahclaws/blob/main/checkpoint/store.py): snapshot store · Snapshots conversation and file state for rewind. · `checkpoint/store.py`
- [Tasks](https://github.com/saferl-lab/cheetahclaws/blob/main/task/store.py): task graph · Dependency-aware task storage and task tools. · `task/store.py`

### Extensibility

Tools, skills, plugins, and MCP integration.

- [Tool Registry](https://github.com/saferl-lab/cheetahclaws/blob/main/tool_registry.py): tool bus · Registers and dispatches tools into a uniform agent interface. · `tool_registry.py`
- [Core Tools](https://github.com/saferl-lab/cheetahclaws/blob/main/tools/fs.py): built-in tools · Filesystem, shell, web, notebook, browser, email, and interaction tools. · `tools/fs.py`
- [Skills](https://github.com/saferl-lab/cheetahclaws/blob/main/skill/executor.py): workflow skills · Reusable markdown skills and command-driven behaviors. · `skill/executor.py`
- [Plugins](https://github.com/saferl-lab/cheetahclaws/blob/main/plugin/loader.py): extension loading · Loads and manages external plugins. · `plugin/loader.py`
- [MCP Bridge](https://github.com/saferl-lab/cheetahclaws/blob/main/cc_mcp/client.py): mcp integration · MCP client, config, and tool adaptation layer. · `cc_mcp/client.py`

### Domain Modules

Specialized vertical workflows built on the core platform.

- [Vertical Apps](https://github.com/saferl-lab/cheetahclaws/blob/main/modular/base.py): domain platform · Specialized workflows built atop the assistant core. · `modular/base.py`

### Ops & Safety

Reliability, limits, and observability.

- [Health](https://github.com/saferl-lab/cheetahclaws/blob/main/health.py): ops · Service health checks. · `health.py`
- [Quota](https://github.com/saferl-lab/cheetahclaws/blob/main/quota.py): guardrail · Usage and rate limit enforcement. · `quota.py`
- [Circuit Breaker](https://github.com/saferl-lab/cheetahclaws/blob/main/circuit_breaker.py): reliability · Failure containment around unstable operations. · `circuit_breaker.py`
- [Error Classifier](https://github.com/saferl-lab/cheetahclaws/blob/main/error_classifier.py): diagnostics · Categorizes failures for handling and reporting. · `error_classifier.py`
- [Logging](https://github.com/saferl-lab/cheetahclaws/blob/main/logging_utils.py): observability · Shared logging utilities. · `logging_utils.py`

## Connections

- Main CLI → Bootstrap: boot · Initializes runtime and environment.
- Main CLI → Agent Loop: launch · Starts the primary agent loop.
- Runner → Agent Loop: runs · Executes agent sessions and turns.
- Agent Loop → Providers: calls model · Sends prompts and receives streamed output.
- Providers → Config: selects backend · Uses configuration to choose and tune providers.
- Agent Loop → Context: builds prompt · Assembles turn context before model invocation.
- Context → Compaction: reduces · Compacts older context when needed.
- Context → Session Store: loads state · Reads session state and conversation history.
- Context → Memory: injects memory · Includes persistent memory in the prompt.
- Context → Checkpointing: reads snapshots · Can pull checkpointed state into context.
- Agent Loop → Tool Registry: uses tools · Dispatches tool calls through the registry.
- Tool Registry → Core Tools: routes core tools · Exposes built-in execution capabilities.
- Tool Registry → Skills: enables skills · Lets skills shape tool availability and flow.
- Tool Registry → Plugins: loads plugins · Adds externally defined tool surfaces.
- Tool Registry → MCP Bridge: bridges mcp · Adapts MCP servers into tools.
- Commands → Skills: switches modes · Commands activate workflows and permissions.
- Commands → Checkpointing: manages · Exposes checkpoint-related actions.
- Commands → Memory: manages · Exposes memory-related actions.
- Terminal UI → Runner: drives · Terminal UI feeds turns into the runner.
- Web App → Runner: drives · Web requests are translated into agent runs.
- Bridges → Runner: routes messages · External channel adapters invoke agent turns.
- Subagents → Agent Loop: delegates to · Spawns delegated agent executions.
- Multi-Agent → Subagents: coordinates · Implements multi-agent and worker patterns.
- Monitor → Runner: schedules · Runs background and proactive jobs through the agent stack.
- Vertical Apps → Tool Registry: extends · Domain workflows add tools and commands.
- Vertical Apps → Skills: uses skills · Specialized vertical workflows rely on reusable skills.
- Agent Loop → Quota: checks limits · Applies usage constraints during execution.
- Agent Loop → Circuit Breaker: guards · Contains repeated failures and unstable tool paths.
- Agent Loop → Error Classifier: classifies errors · Routes failures into structured categories.
- Web App → Logging: logs · Web runtime uses shared observability utilities.
- Agent Loop → Health: reports health · Exposes runtime readiness and liveness signals.
