
Overview
In this guide, you’ll build CLARK, an autonomous AI agent that thinks, learns, and evolves continuously. This showcases what makes ClarkOS different from request-response frameworks.What CLARK Does
- Runs autonomously on 5-minute tick cycles
- Forms 5 types of memories (episodic, semantic, emotional, procedural, reflection)
- Detects patterns and generates “moments of brilliance”
- Self-reflects on its own state and learning
- Creates daily journal entries
- Evolves mood, health, and routine over time
This is not a chatbot. CLARK doesn’t wait for messages—it thinks continuously.
Prerequisites
- Node.js 18+
- OpenRouter API key (LLM)
- Gemini API key (embeddings, free tier)
Step 1: Create Project
Clone the repository and navigate to the example agent:.env.local with your API keys:
OPENROUTER_KEY— LLM accessGEMINI_API_KEY— EmbeddingsTICK_TOKEN— Authentication (generate withopenssl rand -hex 32)
Step 2: Deploy to Convex
ClarkOS runs on Convex serverless infrastructure.Sign up for Convex
Create a free account at convex.dev if you don’t have one.
Start development server
Deploy to production
Step 3: Define Character
Create a character file that defines CLARK’s personality, interests, and voice. Reference: Seeconvex/character.ts in the template.
| Property | Purpose |
|---|---|
name | Agent identifier |
traits | Personality characteristics |
interests | What the agent pays attention to |
voice | Communication style guidelines |
Step 4: Understand State Model
ClarkOS agents maintain rich internal state:| Field | Description |
|---|---|
mood | contemplative, expressive, curious, reflective, concerned |
health | 0-100, depletes with activity, recovers with rest |
routine | morning, day, evening, overnight |
volatility | How much state fluctuates |
cryo | Hibernation mode when health critical |
AgentState interface in src/types.ts
Step 5: Memory Types
CLARK uses all 5 memory types:| Type | Example | Dedup Threshold |
|---|---|---|
| Episodic | ”Read article about AI” | 0.92 |
| Semantic | ”Convex is serverless” | 0.95 |
| Emotional | ”Excited about this” | 0.88 |
| Procedural | ”Morning news is noisy” | 0.97 |
| Reflection | ”I’m analytical at night” | 0.90 |
convex/schema.ts
Step 6: Tick Cycle
Each tick follows this flow:- Load current state
- Calculate routine from time
- Gather relevant memories
- Process through consciousness layer
- Generate LLM response
- Store new memories
- Maybe generate reflection (every 10 ticks)
- Commit state changes
convex/tick.ts for implementation pattern.
Step 7: Consciousness Layer
The consciousness layer filters noise and detects patterns:- Filtering — Removes low-value inputs
- Entity extraction — Identifies key topics
- Pattern detection — Finds common themes
- Brilliance check — Flags significant insights
convex/consciousness.ts pattern.
Step 8: Self-Reflection
Every 10 ticks, CLARK generates a reflection:- Gather recent emotional memories
- Identify procedural patterns
- Prompt LLM for metacognitive insight
- Store as reflection-type memory
convex/reflection.ts pattern.
Step 9: Daily Journals
At midnight, CLARK consolidates the day’s experiences:- Gather all memories from past 24 hours
- Count brilliant thoughts
- Generate narrative summary
- Store as journal entry
convex/journal.ts pattern.
Step 10: Scheduled Execution
Set up crons for automatic operation:Step 11: Run
- Tick logs every 5 minutes
- Memory growth across types
- Reflections every 10 ticks
- Daily journals at midnight
Querying CLARK
What You’ve Built
| Feature | Description |
|---|---|
| Continuous operation | Thinks every 5 minutes autonomously |
| 5 memory types | Events, facts, feelings, patterns, insights |
| Consciousness layer | Filters noise, detects patterns |
| Moments of brilliance | Recognizes significant convergences |
| Self-reflection | Metacognitive observations |
| Daily journals | Consolidates experiences |
| State evolution | Mood and health change naturally |