# Crimson-Heart [English](README.md) | [įŽ€äŊ“中文](README_zh.md) > **A persistent multimodal desktop agent that can listen, observe, speak, remember, use tools, and be interrupted naturally during interaction.** Crimson-Heart is an independently developed local desktop agent. It combines voice interaction, screen understanding, persistent memory, tool use, desktop context, and optional distributed Brain / Body deployment in one long-running system. Unlike a simple request-response chatbot, Crimson-Heart keeps an explicit runtime state, handles user barge-in, coordinates background work with foreground requests, and can separate GPU-heavy inference from local perception and interaction. --- ## What It Can Do - đŸŽ™ī¸ **Voice interaction** with local speech recognition and TTS - đŸ‘ī¸ **Screen understanding** with Qwen2-VL - 🧠 **Persistent semantic memory** with ChromaDB - đŸ› ī¸ **Tool use** for search, calculation, files, notes, system actions, memory, and restricted Python execution - ⚡ **User barge-in** during active reasoning or speech - đŸ–Ĩī¸ **Desktop context** from the active window and optional clipboard context - 🎭 **VTube Studio integration** driven by an internal PAD-inspired state - 🌐 **Brain / Body mode** for separating local interaction from GPU inference --- ## Runtime Preview

Crimson-Heart runtime

A real local runtime session combining desktop code, live agent logs, multimodal interaction, and VTube Studio integration.

--- ## Quick Start ### 1. Clone ```bash git clone https://github.com/YEYVHAIOU/Crimson-Heart.git cd Crimson-Heart ``` ### 2. Install dependencies ```bash pip install -r requirements.txt ``` ### 3. Configure the runtime Copy the example configuration: ```bash copy env.example .env ``` The default main model is: ```text CRIMSON_MODEL_PATH=Qwen/Qwen2.5-7B-Instruct ``` You can replace it with another Hugging Face-compatible causal language model. Important defaults: ```text CRIMSON_SERVER_HOST=localhost CRIMSON_SERVER_BIND=127.0.0.1 CRIMSON_SERVER_PORT=8000 CRIMSON_ENABLE_CLIPBOARD_CONTEXT=false CRIMSON_ENABLE_INTERACTION_LOGGING=false CRIMSON_ALLOW_DESTRUCTIVE_SYSTEM_ACTIONS=false ``` ### 4. Run Local all-in-one mode: ```bash python main.py ``` Persistent desktop mode: ```bash python daemon.py ``` Split Brain / Body mode: ```bash python server.py ``` and on the local interaction machine: ```bash python body.py ``` > Crimson-Heart was primarily developed for Windows desktop use. Core Python components are less platform-specific, but system control, audio, and VTube Studio integration should currently be considered Windows-first. --- ## How It Works ```mermaid flowchart TB subgraph BODY["Body / Client"] MIC["Voice / VAD / Faster-Whisper"] SCREEN["Screen Capture"] CONTEXT["Active Window + Optional Clipboard"] TTS["Edge-TTS / Audio Output"] VTS["VTube Studio"] end subgraph BRAIN["Brain / Server"] SCHED["Runtime State Machine + P0-P3 Scheduler"] LLM["Local LLM"] TOOLS["Tool Dispatcher"] VISION["Qwen2-VL"] MEMORY["Short-Term + ChromaDB Memory"] EMOTION["PAD-Inspired Internal State"] end MIC -->|"voice / barge-in"| SCHED SCREEN --> VISION CONTEXT --> SCHED SCHED --> LLM LLM --> TOOLS TOOLS --> LLM LLM <--> MEMORY SCHED --> EMOTION LLM --> TTS EMOTION --> VTS BODY <-->|"WebSocket"| BRAIN ``` The system can run entirely on one machine or split into two roles: **Brain / Server** - LLM inference - runtime state management - priority scheduling - tool orchestration - memory - visual-language analysis **Body / Client** - speech recognition - screen capture - active-window context - optional clipboard context - TTS - VTube Studio interaction This makes it possible to keep desktop perception and interaction local while moving GPU-heavy inference to another machine. --- ## Runtime Design ### Explicit State Machine Crimson-Heart uses explicit runtime states rather than coordinating behavior through loosely coupled flags. ```text OFFLINE IDLE LISTENING TRANSCRIBING THINKING EXECUTING_TOOL SPEAKING INTERRUPTED ``` Normal state transitions are validated by the scheduler, while exceptional cases such as interruption or disconnect can use controlled forced transitions. ### P0–P3 Priority-Aware Scheduling Pending tasks are divided into four levels: | Priority | Purpose | |---|---| | `P0_SYSTEM_INTERRUPT` | interruption and emergency runtime control | | `P1_USER_REQUEST` | direct user requests | | `P2_SYSTEM_CALLBACK` | internal callbacks and tool/vision results | | `P3_BACKGROUND` | low-priority background work | The queue controls which **pending** task runs next. It is not a claim of general transparent preemption or arbitrary task resumption. ### User Barge-In When the user interrupts active reasoning or speech: 1. the shared stop signal is set immediately; 2. stale pending work is cleared; 3. interruption handling is serialized through the scheduler worker; 4. the runtime enters `INTERRUPTED`; 5. it returns to `LISTENING` for the new request. Streaming generation and relevant execution paths observe the same interruption signal. This is **interruptible execution with runtime recovery**, not continuation of the interrupted task from its previous execution point. ### Bounded Tool Loop The model can call tools through a bounded reasoning/action loop: ```text reason ↓ detect tool call ↓ EXECUTING_TOOL ↓ execute ↓ inject observation ↓ THINKING ``` The explicit iteration limit helps prevent repeated tool loops from consuming resources indefinitely. --- ## Memory and Context Crimson-Heart combines: - short-term conversational state; - persistent vector memory through **ChromaDB**; - semantic recall before generation; - screen snapshots; - active-window context; - optional clipboard context; - continuous voice interaction. Clipboard context is disabled by default because copied text may contain sensitive information. --- ## Restricted Python Execution Crimson-Heart includes a restricted local Python execution layer for model-generated code. Current protections include: - AST-based rejection of selected dangerous constructs; - restricted builtins; - blocked high-risk imports; - filesystem access confined to the executor sandbox; - caller-side timeout reporting. > **This is not an OS-level security sandbox.** The timeout prevents the caller from waiting indefinitely, but it does not forcibly terminate a running Python worker thread. This layer should therefore be treated as defense-in-depth for a local prototype, not as a strong isolation boundary for untrusted code. --- ## Project Structure ```text Crimson-Heart/ ├── config/ # runtime and model configuration ├── core/ # agent loop, scheduler, LLM engine, local logging ├── interfaces/ # console / WebSocket-facing interfaces ├── memory/ # short-term and persistent memory ├── senses/ # speech input and related components ├── tools/ # tool dispatcher and implementations ├── tests/ # lightweight runtime smoke test ├── main.py # local all-in-one mode ├── daemon.py # persistent desktop mode ├── server.py # Brain / GPU-side service ├── body.py # Body / local perception and interaction ├── env.example ├── requirements.txt └── LICENSE ``` --- ## Validation A lightweight runtime smoke test is included: ```bash python tests/runtime_smoke_test.py ``` It does **not** load the main language model or vision model and does not start audio or network services. It checks: - P0–P3 queue ordering; - legal and illegal state transitions; - P0 interruption and serialized recovery; - restricted Python execution; - compact tool-call parsing and stripping; - project/data filesystem boundaries; - interaction logging being disabled by default. Full multimodal operation still depends on the configured models, desktop environment, audio devices, and optional VTube Studio setup. --- ## Safety and Privacy Defaults Crimson-Heart is a research and engineering prototype, not a production security boundary. The public version uses conservative defaults: - Brain Server binds to `127.0.0.1` by default; - clipboard context is disabled by default; - interaction logging is disabled by default; - destructive system actions such as `PROCESS_KILL` and `LOCK` require explicit opt-in; - weather lookup requires an explicit location rather than inferring one from public IP; - File Tool reads are limited to the project tree, while writes/deletes are further limited to `data/`; - Python Executor filesystem access is limited to `sandbox/`; - local secrets such as `.env` and `token.txt` are excluded from version control. The current WebSocket prototype does **not** provide production-grade authentication or TLS. Do not expose the Brain Server directly to an untrusted network. --- ## Project Evolution Crimson-Heart began as a personal exploration of a persistent local AI companion. Over roughly **six months of iteration**, the project evolved from integrating individual multimodal capabilities toward runtime-level problems such as state management, user interruption, tool execution, persistent context, resource coordination, and Brain / Body separation. Earlier development was primarily conducted locally before the project was consolidated into this public repository, so the public commit history does not represent the complete development timeline. The project still keeps its original digital-life motivation, but the current version puts more emphasis on the underlying agent runtime and system design. --- ## Scope and Limitations Crimson-Heart is intended to demonstrate a working evolving system rather than a production-grade or state-of-the-art agent framework. Current limitations include: - interrupted tasks do not transparently resume from the previous execution point; - WebSocket communication has no production-grade authentication or TLS; - restricted Python execution is not OS-level isolation; - desktop automation is sensitive to operating-system and UI conditions; - local multimodal inference can be resource intensive; - the project has not been systematically evaluated on a general-purpose agent benchmark. --- ## Author Crimson-Heart is an **independent personal project**. I designed and implemented the system architecture and its main runtime components, including state management, priority-aware scheduling, interruption handling, tool integration, multimodal desktop context, memory integration, local/distributed runtime modes, desktop interaction, voice processing, and internal emotion-state integration. The project builds on existing open-source models and libraries for inference, speech, vector storage, desktop interaction, and UI integration. Its contribution is primarily in **system integration and runtime/control design** rather than in proposing a new foundation model or training algorithm. --- ## License MIT License. See [LICENSE](LICENSE).