CharacterOS is powered by a multi-agent orchestrated network of 25+ specialized agents organized into 5 families. Each agent excels at a specific task: content generation, quality assurance, audio production, supporting services, and personality evolution.
Story Q&A with RAG + chapter citations
Canon-locked character roleplay
Multi-character scene generation
Narrative framing & transitions
AgentRuntime in services/characteros/agent_runtime.py is the central orchestrator. It's a singleton (always use get_agent_runtime_singleton() — never instantiate per-request). The runtime imports and manages all 25+ agents, lazy-initializing them on first use to minimize startup time.
Agents communicate through typed contracts, RAG retrieval, and shared memory bridges. Key patterns:
Each agent follows a consistent lifecycle: initialization (lazy on first use), validation (typed contracts at boundaries), telemetry (@traced decorator on all public methods), error handling (CharacterOSError codes), memory persistence (non-blocking MemoryBridge calls).
All agents use sanitize_story_excerpts() when handling RAG results, dump_validated() for response contracts, @traced for telemetry, and BatchEmbeddingService for cached embeddings. Parallel TTS calls are guarded with asyncio.Semaphore(5) to prevent memory exhaustion.
These agents create story content: ReaderAgent answers story questions with RAG, CharacterAgent generates character dialogue locked to canon, WriterAgent creates multi-character scenes (max 5), and NarratorAgent adds narrative framing.
These agents validate content: ContinuityAgent checks 5 layers (traits, relationships, timeline, dialogue, spoilers), DialogueQualityAgent scores naturalness, EmotionalBeatAnalyzer tracks character arcs, and ScenePacingOptimizer balances action and dialogue.
These agents handle voice and audio production: VoiceSelectionAgent maps character traits to voice DNA, VoiceConfigurationAgent adjusts 300+ voice settings (speed, pitch, emotion), AudioSceneAgent parses dialogue and detects emotion per line, VoiceVault IP-locks voice DNA to projects.
These agents provide orchestration and utility: DirectorAgent injects mood and pacing, AtmosphereAgent adds context about setting and tone, CharacterParticipantManager generates character reactions in collaboration sessions.
These agents enable personality growth: EmotionalArcEvolverAgent computes character evolution from reactions, ConsensusAnalyzerAgent detects when multiple writers describe the same character differently and synthesizes a unified voice.