How saferl-lab/cheetahclaws works
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 Agent Loop · tool_registry.py Tool Registry · context.py Context · agent_runner.py Runner
Components 30
Runtime Core
Startup, orchestration, and execution loop.
- Main CLI · Primary process bootstrap and mode selection.
cheetahclaws.py - Agent Loop · Core turn loop coordinating model calls, tools, and streamed events.
agent.py - Runner · Execution harness for agent sessions and background runs.
agent_runner.py - Bootstrap · Startup wiring and environment initialization.
bootstrap.py - Providers · Model backends and provider-specific behavior.
providers.py - Config · Runtime configuration and provider selection.
cc_config.py - Subagents · Delegated agent execution and handoff patterns.
subagent.py - Multi-Agent · Brainstorming and worker pipeline coordination.
multi_agent/subagent.py - Monitor · Scheduling, notifications, summarization, and fetchers.
monitor/scheduler.py
Interfaces
User-facing entry points and message bridges.
- Terminal UI · REPL input and terminal rendering.
ui/input.py - Web App · Browser chat UI, auth, API, and session-backed server.
web/server.py - Bridges · Slack, Telegram, WeChat, and interactive session adapters.
bridges/slack.py - Commands · Command surface for plan, checkpoint, memory, agent, and config actions.
commands/core.py
State & Context
Conversation context, persistence, and task state.
- Context · Builds turn context from state, workspace, and instructions.
context.py - Compaction · Shrinks older context before model requests.
compaction.py - Session Store · Persists session-level conversation and runtime state.
session_store.py - Memory · User and project memory management.
memory.py - Checkpointing · Snapshots conversation and file state for rewind.
checkpoint/store.py - Tasks · Dependency-aware task storage and task tools.
task/store.py
Extensibility
Tools, skills, plugins, and MCP integration.
- Tool Registry · Registers and dispatches tools into a uniform agent interface.
tool_registry.py - Core Tools · Filesystem, shell, web, notebook, browser, email, and interaction tools.
tools/fs.py - Skills · Reusable markdown skills and command-driven behaviors.
skill/executor.py - Plugins · Loads and manages external plugins.
plugin/loader.py - MCP Bridge · MCP client, config, and tool adaptation layer.
cc_mcp/client.py
Domain Modules
Specialized vertical workflows built on the core platform.
- Vertical Apps · Specialized workflows built atop the assistant core.
modular/base.py
Ops & Safety
Reliability, limits, and observability.
- Health · Service health checks.
health.py - Quota · Usage and rate limit enforcement.
quota.py - Circuit Breaker · Failure containment around unstable operations.
circuit_breaker.py - Error Classifier · Categorizes failures for handling and reporting.
error_classifier.py - Logging · Shared logging utilities.
logging_utils.py
Connections 31
- 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.