Architecture & Orchestration
The CEO-Expert model, Heartbeat engine and the Zero-Human Company concept.
Core Orchestration Architecture
OpenCognit uses a Planner → Executor → Critic → Self-Heal pipeline:
| Feature | What it does |
|---|---|
| Native Tool Calls | CEO uses Anthropic/OpenAI function-calling API instead of JSON-in-text. Structured, reliable action extraction. |
| Critic / Evaluator Loop | Every task result is reviewed by a lightweight evaluator (Haiku). If output is insufficient, the agent retries (max 2 rejections). After 2 rejections, the task is set to blocked and flagged for human review — never silently auto-approved. |
| Dual-Engine Quality Gate | Both execution paths — heartbeat and scheduler timer — pass through the Critic gate. update_task_status→done actions from the scheduler are reviewed before the task closes. |
| Self-Healing Retry | On non-transient failure: auto-retry with exponential backoff (5 → 15 → 45 min). After 3 failures: escalation task created for CEO, original task marked blocked. |
| Orchestrator Escalation | When a task exceeds max retries, the CEO gets a high-priority escalation task with full failure context and remediation suggestions — woken up immediately. |
| Task-Output-as-Input | When a task depends on prior tasks, those outputs are passed as context automatically. No agent needs to re-discover previous results. |
| Parallel Wakeups | All agents triggered by one CEO decision fire simultaneously via Promise.all — no staggered delays. |
| SOUL.md Identity | File-based agent identity with Markdown, template variables ({{company.name}}), and mtime-based cache invalidation. Replaces static system prompts. |
| LRU Conversation Memory | In-memory conversation history uses true last-access-time eviction — the least recently used session is dropped first, not the oldest-inserted one. |
| BM25 Memory | Memory retrieval uses BM25+ scoring (Robertson–Zaragoza) with German/English stopword filtering. Finds contextually relevant memories, not just keyword matches. |
| Cleanup & Backup | Automatic TTL-based data cleanup (every 6h) + daily SQLite hot-backup with 7-day retention. Session files auto-deleted after 7 days. Zero maintenance for self-hosters. |
| DB Performance Indexes | 9 indexes on hot-query columns (agent inbox, task status, wakeup queue, etc.) — queries that previously scanned entire tables now use index lookups. |
The Zero-Human Company Model
OpenCognit implements a hierarchical multi-agent architecture modeled after real company structures. Instead of using a single all-in-one agent, specialized AI experts work together in roles — coordinated by a CEO agent.
graph TB
Board["👤 Board (Human)"]
CEO["🤖 CEO Agent\nOrchestrator"]
Dev["🔧 Dev Expert\nFrontend/Backend"]
Research["🔍 Research Expert\nMarket & Data"]
DevOps["⚙️ DevOps Expert\nInfrastructure"]
DB[(SQLite\nDatabase)]
Board -->|Strategic goal| CEO
CEO -->|Delegate task| Dev
CEO -->|Delegate task| Research
CEO -->|Delegate task| DevOps
Dev -->|Result + comment| CEO
Research -->|Result + comment| CEO
DevOps -->|Result + comment| CEO
CEO -->|Status report| Board
CEO <--> DB
Dev <--> DB
Research <--> DB
DevOps <--> DBRole Hierarchy
CEO Agent (Central Orchestrator)
The CEO is a special agent with adapter type ceo. It:
- Receives high-level goals from the board (humans)
- Breaks goals into concrete tasks (sub-tasks)
- Delegates tasks to the best-matching expert based on skills
- Reviews completed tasks for quality
- Escalates blocked tasks to managers or board
- Recommends new hires when capacity is missing
Experts (Specialized Agents)
Each expert has:
- Role & Title — e.g.
Senior Frontend Developer - Skills — tags like
react,typescript,css - Connection type — which LLM provider is used
- Manager — optional: who to report to (
reportsTo) - Budget — monthly token cost budget
Experts work autonomously: once a task is assigned, the Heartbeat engine picks it up.
The Heartbeat Engine
The heartbeat is the core of autonomy in OpenCognit. It allows agents to work without human prompts continuously.
sequenceDiagram
participant S as Scheduler (30s)
participant W as Wakeup Service
participant H as Heartbeat Service
participant A as Adapter (Claude/etc.)
participant DB as Database
S->>W: Who needs a wakeup?
W->>DB: Fetch pending wakeup requests
DB-->>W: [Agent A: Task #12, Agent B: Timer]
W->>H: triggerCycle(Agent A)
H->>DB: Create arbeitszyklen entry
H->>DB: Fetch agent inbox (open tasks)
DB-->>H: [Task #12: "Implement login page"]
H->>DB: Set execution lock (30min timeout)
H->>A: Execute task (prompt + context)
A-->>H: Result + token usage
H->>DB: Post comment on task
H->>DB: Update task status (done/blocked)
H->>DB: Record costs
H->>DB: Release lockWakeup Sources
Agents are woken up by various events:
| Source | Description |
|---|---|
timer | Regular heartbeat cycle (configurable per agent) |
assignment | A new task was assigned to the agent |
on_demand | Manual trigger via dashboard or API |
automation | Routine trigger (cron-based) |
Coalescing: Multiple wakeup requests for the same agent and task are merged into a single one (deduplication) to avoid unnecessary executions.
Execution Lock
Each task can only be worked on by one agent at a time. The lock contains:
executionRunId— ID of the active heartbeat runexecutionAgentNameKey— Normalized agent nameexecutionLockedAt— Lock timestamp- Timeout: 30 minutes — lock is automatically released after that
CLI Lock Safety
The Claude Code adapter uses two separate mutexes with a 5-minute timeout:
| Lock | Scope | Purpose |
|---|---|---|
agent | Autonomous heartbeat runs | Prevents concurrent agent executions |
chat | Interactive Telegram/chat sessions | Prevents chat from blocking agent runs |
Separating the locks ensures a long-running chat session cannot starve the heartbeat — and vice versa. A 5-minute timeout prevents deadlocks if either path crashes mid-execution.
Adapter System
OpenCognit uses an adapter pattern for polymorphic execution. Each expert can connect to a different LLM provider:
| Adapter | Description | Special feature |
|---|---|---|
claude | Claude API (Anthropic) | Direct API calls |
claude-code | Claude Code CLI | Session persistence via files |
openrouter | OpenRouter | Access to 100+ models |
ollama | Local models | No cloud dependency |
openai | OpenAI API | GPT models |
bash | Shell commands | Timeout: 5 min, blocked commands |
http | HTTP requests | External API integration |
ceo | CEO orchestration | Auto-delegation & strategy |
SOUL.md — File-Based Agent Identity
SOUL.md is an optional, git-trackable Markdown file that replaces the system prompt stored in the database.
# {{agent.name}} — {{agent.role}}
You work at {{company.name}}.
{{company.goal}}
## Your principles
- Be concise and precise
- Always finish tasks completelyTemplate variables available:
{{agent.name}}— Agent's name{{agent.role}}— Agent's role description{{company.name}}— Company name{{company.goal}}— Company goal
How it works: The file is loaded before each task execution. Caching is based on the file's mtime — the file is only re-read when it changes. You can export an agent's current system prompt as a SOUL.md via Expert Settings → Export SOUL.md.
SOUL.md files can be version-controlled with Git, shared across teams, or swapped dynamically for A/B testing agent personas.
Semantic Memory
Each agent has a 5-layer memory system:
| Layer | Content | Retention |
|---|---|---|
| Wings | One "room" per expert | Permanent |
| Drawers | Topic-based knowledge ([room] content) | Permanent |
| Diary | Action logs, decisions, knowledge | Rotates: keep last N |
| KG | Typed facts (subject → predicate → object) | Until invalidated |
| Summaries | AI-generated compact summaries | Hourly consolidation |
BM25+ Retrieval: When a task starts, the agent's memory is searched using BM25+ scoring (Robertson–Zaragoza variant). Documents are ranked by term frequency × inverse document frequency, with document-length normalization. German and English stopwords are filtered.
Agents can write to their memory using [REMEMBER:room] tags in their output:
Done! The API endpoint is at /api/v2/users.
[REMEMBER:api_endpoints] /api/v2/users — GET, returns paginated user listMaintenance: Cleanup & Backup
OpenCognit handles its own maintenance automatically:
Cleanup Service (runs every 6 hours)
| Target | Retention |
|---|---|
| Session files | 7 days |
| Successful runs | 30 days |
| Failed runs | 14 days |
| Trace events | 14 days |
| Old summaries | Keep last 3 versions |
| Activity log | 90 days |
| System chat messages | 30 days |
Backup Service (daily)
- Hot backup via SQLite's
sqlite.backup()API — safe during concurrent writes - Stored in
data/backups/opencognit_YYYY-MM-DD.db - 7-day retention (older backups auto-deleted)
Tech Stack
Frontend
React 19, TypeScript, TanStack Query, Tailwind CSS, Shadcn/UI, Vite
Backend
Node.js, Express 5, TypeScript, JWT Auth, WebSocket (ws)
Database
SQLite (better-sqlite3), Drizzle ORM, WAL mode for concurrency
Agent Execution
Adapter pattern: Claude, OpenRouter, Ollama, Bash, HTTP