The AI brain that orchestrates all conversations across every channel
Karen is the central intelligence layer. Every inbound message — whether from WhatsApp, Instagram DM, the website widget, Telegram, or a voice call — is routed through Karen for processing and response.
Required environment variables:
OPENROUTER_API_KEY — OpenRouter authenticationOPENROUTER_MODEL — model string (e.g. anthropic/claude-3-5-sonnet)GEMINI_API_KEY — free pool Gemini keyGEMINI_PAID_KEY — paid Gemini fallbackKaren AI is the active intelligence in every patient journey:
src/ai.js — Orchestrator. Entry point: chat() at line 125. Re-exports from all AI sub-modules. Note: this is the split version locally (547 lines) — server runs the monolithic version (2300+ lines).src/context-builder.js — Assembles memory, permissions, and conversation history into the prompt context. Entry: buildContext() at line 20.src/prompt-builder.js — Constructs the full system prompt and selects which actions are available for the current context. Key exports: buildDefaultPrompt() (line 217), selectActionsForContext().src/model.js — OpenRouter API calls and response parsing. Key exports: callOpenRouter(), parseActionTags(), classifyComplexity().src/reflection.js — Post-generation self-evaluation. Key exports: shouldTriggerReflection(), reflectOnResponse().src/prompts.js — All prompt template constants: AVAILABLE_ACTIONS, MEMORY_INSTRUCTIONS, ACTION_CATEGORIES.src/gemini.js — Gemini API client for cheaper task routing.ssh hetzner and pull the current file before making changes.
src/core_memory.js related to owner_tenant_id. This affects how per-tenant core memory (persona, goals) is read back. Do not rely on getCoreMemory() returning the correct owner context until this is patched.