Decoupling Soul, Body, and Voice: Multi-Process Architecture for a Desktop AI Companion
How OpenPet separates character identity from rendering engines using a single Zod protocol, sandboxed Electron processes, incremental streaming behavior parsing, and an Obsidian-compatible memory wiki.
Most desktop AI apps wrap a web chat box in a window, while classic desktop pets lack real memory, tool execution, and multi-provider intelligence. From day one, OpenPet has been built around a single architectural split:
One resident desktop character = Soul (how it thinks and remembers) + Body (how it renders and moves) + Voice (how it speaks and listens).
Treating that boundary as a first-class engineering contract shapes the entire process topology, storage format, and community ecosystem.
Single Source of Truth in packages/protocol
Multi-window Electron apps decay quickly when IPC payloads drift across processes. OpenPet centralizes every cross-boundary schema in packages/protocol using Zod as the single source of truth shared by Main, Renderers, and Workers:
- Local IPC: JSON-RPC 2.0 exposed exclusively through a narrow Preload
contextBridge(window.openpet.rpc / on), withsandboxandcontextIsolationstrictly enabled on every renderer. - Inline LLM Behavior Protocol: incremental tags (
<emo />,<act />,<wait />) and intent headers embedded directly in streaming completions. - Layered Package Splits: formal manifest boundaries separating full
.dspackarchives,.dssoulpersona packages, and.dsbodyvisual rigs.
Because that split lives as typed protocol constants, users can hot-swap a character across VRM 3D (three-vrm), Live2D, and 2D frame atlases (pixi) without changing characterId—keeping conversations, personas, and long-term memory completely intact.
Dual-Track Streaming Pipeline
Every incoming message—from the floating chat overlay, Hub window, or QQ / Telegram IM bridges—flows through one low-latency pipeline in ChatService:
- Parallel Context Assembly:
ContextPipelinequeries local SQLite WAL RAG vectors, the Markdown memory wiki, worldbook entries, and conversation summaries concurrently. - Dual-Track Token Routing: an isolated Provider Worker streams chunks back to Main; clean prose streams into the chat bubble while
BehaviorParserincrementally intercepts<emo/>and<act/>cues and broadcasts live expression, gesture, gaze, and pause commands to the transparent character window. - Guarded MCP Tools: tool requests pass through the MCP Manager authorization gate and execute inside dedicated stdio/SSE subprocesses with full argument and result visibility.
Thin Main Process & Supervised Worker Isolation
A desktop companion stays open all day; a misbehaving third-party plugin or stalled upstream provider must never freeze the desktop shell.
- Provider Workers (
worker_threads) isolate OpenAI, Anthropic, Gemini, and Ollama streaming adapters behind exponential-backoff crash supervision. - Per-Plugin Workers sandbox desktop extensions with explicit permission prompts—and API secrets never enter plugin worker threads.
- Dumb Character Renderer: the transparent always-on-top avatar window focuses solely on alpha hit-testing, physics drag, and animation playback without holding business state.
Why Long-Term Memory Is an Obsidian-Compatible Markdown Wiki
Opaque vector stores make it impossible for users to inspect or correct what an AI remembers. OpenPet stores cross-character user profiles and per-character relationship logs as plain Markdown notes backed by SQLite indexing and a backlink graph—the memory directory itself opens natively as an Obsidian vault. Every memory links back to its source conversation, and consolidation checkpoints persist safely even across sudden exits.
Turning “desktop presence” into typed schemas, crash-isolated workers, and inspectable local files is what makes OpenPet both expressive and resilient.