Date: 2026-01-16 Goal: Build memos-compatible agent in Gerbil Scheme Strategy: Gerbil-first, leverage existing resources, incremental delivery
Build a self-evolving AI agent that uses memos' memory architecture to achieve true stateful evolution, with:
- Autonomous Evolution: Agent can modify its own code during sleep-time compute
- Stateful Memory: Agent remembers evolution history and reflects on changes
- Safe Experimentation: Shadow testing via Elixir supervision (Phase 0)
- Evolution Tools: Self-modification, performance analysis, rollback capabilities
- Core Memory Blocks: Stable identity with editable persona/human memory
- Archival Memory: Long-term storage for evolution history and learnings
- Sleep-time Compute: Autonomous thinking and evolution without human intervention
- Active Memory Management: Agent can modify its own knowledge base
- Multiple LLM provider support (OpenAI, Anthropic, Groq, Ollama, etc.)
- Custom tool execution with sandbox
- REST API for agent management
- PostgreSQL persistence with pgvector
- Fault tolerance via Elixir supervision
Phase 0: Elixir Supervision Layer (~2,000 lines)
- GerbilManager, MemoryVault, WALManager
- HealthMonitor, EvolutionArbiter, TrafficSplitter
- Docker deployment, CI/CD pipeline
Phase 1: Gerbil Agent Core (~3,650 lines)
- Agent lifecycle management
- DSL (defagent, deftool, when->)
- State management with context
- Basic memory system
- Tool framework
- Integration tests
Total: ~5,650 lines, 40% foundation complete
- LLM provider integration (0%)
- HTTP server & REST API (0%)
- Database persistence (20% - only checkpoints)
- Message management (10% - basic conversation)
- Advanced memory (30% - missing archival, blocks)
- Core tools (0%)
- Agent execution loop (20% - basic structure)
Goal: Support OpenAI and Anthropic APIs
Tasks:
- Create
gerbil/llm/directory structure - Adapt OpenAI client from gerbil_scheme_book
- Implement
llm/openai.ss:- Chat completions
- Streaming support
- Tool call parsing
- Error handling
- Implement
llm/anthropic.ss:- Messages API
- Streaming support
- Tool use parsing
- Create
llm/types.ss(shared types) - Add tests for both clients
Deliverables:
gerbil/llm/openai.ss(~300 lines)gerbil/llm/anthropic.ss(~300 lines)gerbil/llm/types.ss(~100 lines)- Tests (~200 lines)
Dependencies: None (uses gerbil_scheme_book examples)
Goal: Support Groq, Ollama, and provider abstraction
Tasks:
- Implement
llm/groq.ss(OpenAI-compatible) - Implement
llm/ollama.ss(local models) - Create
llm/client.ss(unified interface):(def (llm-chat-completion provider model messages tools) (case provider ((openai) (openai-chat-completion ...)) ((anthropic) (anthropic-messages ...)) ((groq) (groq-chat-completion ...)) ((ollama) (ollama-generate ...)))) - Add provider configuration management
- Implement provider registry
- Add integration tests
Deliverables:
gerbil/llm/groq.ss(~200 lines)gerbil/llm/ollama.ss(~250 lines)gerbil/llm/client.ss(~400 lines)gerbil/llm/config.ss(~150 lines)- Tests (~300 lines)
Dependencies: Week 1 completion
Goal: Basic HTTP server with routing
Tasks:
- Research Gerbil HTTP server libraries:
:std/net/httpd(standard library)- Third-party options
- Implement
server/http.ss:- HTTP server setup
- Request parsing
- Response generation
- JSON serialization
- Implement
server/router.ss:- Route registration
- Path matching
- Method handling
- Create basic health check endpoint
- Add request logging
- Add error handling middleware
Deliverables:
gerbil/server/http.ss(~400 lines)gerbil/server/router.ss(~300 lines)gerbil/server/middleware.ss(~200 lines)- Tests (~200 lines)
Dependencies: None (uses standard library)
Goal: Core API endpoints for agent management
Tasks:
- Implement
server/routes/agents.ss:POST /v1/agents- Create agentGET /v1/agents/:id- Get agentPATCH /v1/agents/:id- Update agentDELETE /v1/agents/:id- Delete agentGET /v1/agents- List agents
- Implement
server/routes/messages.ss:POST /v1/agents/:id/messages- Send messageGET /v1/agents/:id/messages- Get messages
- Add request validation
- Add response serialization
- Create API documentation
- Add integration tests
Deliverables:
gerbil/server/routes/agents.ss(~500 lines)gerbil/server/routes/messages.ss(~400 lines)gerbil/server/validation.ss(~200 lines)- API documentation (~50 lines)
- Tests (~400 lines)
Dependencies: Week 3 completion
Milestone: Basic agent API working, can create agents and send messages
Goal: PostgreSQL schema and Elixir database layer
Tasks:
- Design database schema (memos-compatible):
CREATE TABLE agents ( id UUID PRIMARY KEY, name TEXT NOT NULL, created_at TIMESTAMP, ... ); CREATE TABLE messages ( id UUID PRIMARY KEY, agent_id UUID REFERENCES agents(id), role TEXT NOT NULL, content TEXT NOT NULL, created_at TIMESTAMP, ... ); CREATE TABLE memory_blocks ( id UUID PRIMARY KEY, agent_id UUID REFERENCES agents(id), label TEXT NOT NULL, value TEXT NOT NULL, is_template BOOLEAN, ... );
- Create Alembic migrations
- Extend Elixir
MemoryVaultfor structured storage - Implement database operations in Elixir:
- Agent CRUD
- Message CRUD
- Memory block CRUD
- Add database connection pooling
- Add transaction support
Deliverables:
- Database migrations (~300 lines SQL)
- Extended Elixir modules (~800 lines)
- Tests (~300 lines)
Dependencies: None (extends Phase 0)
Goal: Gerbil-Elixir database protocol
Tasks:
- Design message protocol for database operations:
;; Gerbil -> Elixir (elixir-send "db_query" (hash 'operation 'insert 'table 'agents 'data (hash 'name "MyAgent" ...))) ;; Elixir -> Gerbil (hash 'type "db_result" 'success #t 'data (hash 'id "uuid" ...))
- Implement
database/client.ss:- Query execution
- Result parsing
- Error handling
- Connection management
- Implement
database/agents.ss(agent operations) - Implement
database/messages.ss(message operations) - Add caching layer
- Add integration tests
Deliverables:
gerbil/database/client.ss(~400 lines)gerbil/database/agents.ss(~300 lines)gerbil/database/messages.ss(~300 lines)- Tests (~400 lines)
Dependencies: Week 5 completion
Goal: Message persistence and retrieval
Tasks:
- Implement
message/manager.ss:- Message creation
- Message retrieval
- Message search (text-based)
- Conversation history
- Message pagination
- Integrate with database client
- Add message validation
- Implement message filtering
- Add message statistics
- Create message utilities
Deliverables:
gerbil/message/manager.ss(~600 lines)gerbil/message/types.ss(~200 lines)- Tests (~300 lines)
Dependencies: Week 6 completion
Goal: Streaming message responses
Tasks:
- Implement
message/stream.ss:- Server-Sent Events (SSE)
- Streaming response generation
- Chunk buffering
- Error handling in streams
- Integrate with LLM streaming
- Add stream lifecycle management
- Implement stream cancellation
- Add streaming tests
Deliverables:
gerbil/message/stream.ss(~400 lines)- Streaming integration (~200 lines)
- Tests (~200 lines)
Dependencies: Week 7 completion
Milestone: Full message system working with persistence and streaming
Goal: Structured memory blocks (memos-compatible)
Tasks:
- Implement
memory/blocks.ss:- Memory block types (persona, human, custom)
- Block CRUD operations
- Read-only protection
- Block templates
- Block validation
- Integrate with database
- Add block versioning
- Implement block search
- Create block utilities
Deliverables:
gerbil/memory/blocks.ss(~500 lines)- Database integration (~200 lines)
- Tests (~300 lines)
Dependencies: Week 6 completion
Goal: Core memory manipulation tools
Tasks:
- Implement
memory/core.ss:core_memory_append- Append to memory blockcore_memory_replace- Replace memory block contentmemory_apply_patch- Apply JSON patch to memory- Memory validation
- Memory constraints
- Integrate with agent core
- Add memory change tracking
- Implement memory rollback
- Add memory tests
Deliverables:
gerbil/memory/core.ss(~400 lines)- Integration (~200 lines)
- Tests (~300 lines)
Dependencies: Week 9 completion
Goal: Long-term memory with semantic search
Tasks:
- Implement
memory/archival.ss:- Archival memory storage
- Memory insertion
- Memory retrieval
- Text-based search (initial)
- Add embedding generation (via LLM API):
(def (generate-embedding text provider) (case provider ((openai) (openai-embeddings text)) ((ollama) (ollama-embeddings text)))) - Integrate with database (text storage)
- Implement memory pagination
- Add memory statistics
Deliverables:
gerbil/memory/archival.ss(~600 lines)- Embedding generation (~200 lines)
- Tests (~300 lines)
Dependencies: Week 10 completion
Goal: Vector-based semantic search
Options:
- Option A: Use pgvector via Elixir
- Option B: Implement in Zig/Rust
- Option C: Use external service (Qdrant, Weaviate)
Recommended: Option A (leverage PostgreSQL)
Tasks:
- Add pgvector extension to PostgreSQL
- Extend Elixir database layer for vector operations
- Implement
memory/search.ss:- Vector similarity search
- Hybrid search (text + vector)
- Search ranking
- Search filtering
- Add search optimization
- Benchmark search performance
Deliverables:
gerbil/memory/search.ss(~400 lines)- Elixir vector operations (~300 lines)
- Tests (~200 lines)
Dependencies: Week 11 completion
Milestone: Complete memory system with blocks, core operations, and archival
Goal: Memos-compatible core tools
Tasks:
- Implement
tools/core.ss:send_message- Send message to userconversation_search- Search conversation historyconversation_search_date- Search by datearchival_memory_insert- Insert to archivalarchival_memory_search- Search archival
- Integrate with message manager
- Integrate with memory system
- Add tool validation
- Add tool tests
Deliverables:
gerbil/tools/core.ss(~500 lines)- Integration (~200 lines)
- Tests (~300 lines)
Dependencies: Week 12 completion
Goal: Memory manipulation tools
Tasks:
- Implement
tools/memory.ss:core_memory_append- Append to core memorycore_memory_replace- Replace core memorymemory_apply_patch- Apply JSON patch- Memory validation in tools
- Memory constraints enforcement
- Add tool documentation
- Add tool examples
- Implement tool helpers
Deliverables:
gerbil/tools/memory.ss(~400 lines)- Documentation (~100 lines)
- Tests (~300 lines)
Dependencies: Week 13 completion
Goal: Isolated tool execution
Tasks:
- Implement
tools/sandbox.ss:- Process isolation
- Resource limits (CPU, memory, time)
- Filesystem restrictions
- Network restrictions
- Add sandbox configuration
- Implement sandbox monitoring
- Add sandbox cleanup
- Test sandbox security
Deliverables:
gerbil/tools/sandbox.ss(~600 lines)- Configuration (~100 lines)
- Tests (~300 lines)
Dependencies: Week 14 completion
Goal: Tool execution constraints
Tasks:
- Implement
tools/rules.ss:run_first- Tool must run firstexit_loop- Tool exits agent looprequires_approval- Tool needs user approvalterminal- Tool is terminal- Rule validation
- Rule enforcement
- Add approval workflow
- Implement rule configuration
- Add rule tests
Deliverables:
gerbil/tools/rules.ss(~400 lines)- Approval workflow (~200 lines)
- Tests (~300 lines)
Dependencies: Week 15 completion
Milestone: Complete tool system with core tools, memory tools, sandbox, and rules
Goal: Memos-compatible agent step execution
Tasks:
- Implement
agent/executor.ss:- Step-based execution
- LLM inference with tools
- Tool call parsing
- Tool execution
- Memory updates
- Response generation
- Add step tracking
- Implement step persistence
- Add step statistics
- Create execution tests
Deliverables:
gerbil/agent/executor.ss(~800 lines)- Step tracking (~200 lines)
- Tests (~400 lines)
Dependencies: Week 16 completion
Goal: Automatic context management
Tasks:
- Implement
agent/context.ss:- Context window calculation
- Message truncation
- Automatic summarization
- Context optimization
- Token counting
- Add summarization triggers
- Implement summarization via LLM
- Add context caching
- Test context management
Deliverables:
gerbil/agent/context.ss(~500 lines)- Summarization (~300 lines)
- Tests (~300 lines)
Dependencies: Week 17 completion
Goal: Streaming agent responses
Tasks:
- Implement
agent/stream.ss:- Streaming step execution
- Streaming tool calls
- Streaming memory updates
- Streaming response generation
- Stream error handling
- Integrate with message streaming
- Add stream lifecycle management
- Implement stream cancellation
- Test streaming execution
Deliverables:
gerbil/agent/stream.ss(~600 lines)- Integration (~200 lines)
- Tests (~300 lines)
Dependencies: Week 18 completion
Goal: Production-ready performance
Tasks:
- Profile agent execution
- Optimize hot paths:
- Message serialization
- Database queries
- LLM API calls
- Memory operations
- Add caching layers
- Implement connection pooling
- Add performance monitoring
- Create performance benchmarks
- Write optimization guide
Deliverables:
- Performance optimizations (~500 lines)
- Benchmarks (~200 lines)
- Documentation (~100 lines)
Dependencies: Week 19 completion
Milestone: Complete agent execution loop with streaming and optimization
| Phase | Component | Lines | Status |
|---|---|---|---|
| 0 | Elixir Supervision | ~2,000 | β Done |
| 1 | Agent Core | ~3,650 | β Done |
| 2 | LLM & HTTP | ~4,300 | β Todo |
| 3 | Database & Messages | ~4,200 | β Todo |
| 4 | Advanced Memory | ~3,100 | β Todo |
| 5 | Tool System | ~3,500 | β Todo |
| 6 | Execution Loop | ~3,500 | β Todo |
| Total | All Components | ~24,250 | 24% Done |
- β Architecture documentation (Phase 0 & 1)
- β³ API documentation (Phase 2)
- β³ Database schema documentation (Phase 3)
- β³ Memory system guide (Phase 4)
- β³ Tool development guide (Phase 5)
- β³ Agent execution guide (Phase 6)
- β³ Deployment guide (Phase 6)
- β Unit tests (Phase 0 & 1): 30+ test cases
- β³ Integration tests (Phase 2-6): ~100+ test cases
- β³ Performance benchmarks (Phase 6)
- β³ End-to-end tests (Phase 6)
- Can call OpenAI, Anthropic, Groq, Ollama APIs
- HTTP server running on port 8283
- Can create agent via REST API
- Can send message to agent via REST API
- PostgreSQL database with schema
- Can persist agents to database
- Can persist messages to database
- Can retrieve conversation history
- Streaming responses working
- Memory blocks working (persona, human, custom)
- Core memory operations working
- Archival memory with search
- Semantic search (optional)
- Core tools working (send_message, search, etc.)
- Memory tools working (append, replace, patch)
- Tool sandbox working
- Tool rules enforced
- Agent step execution working
- LLM inference with tool calls
- Context window management
- Streaming execution
- Performance benchmarks met
| Week | Milestone | Deliverable |
|---|---|---|
| 1 | OpenAI & Anthropic clients | LLM integration |
| 2 | Additional providers | Provider abstraction |
| 3 | HTTP server | Basic server |
| 4 | REST API | Agent API |
| 5 | Database schema | PostgreSQL setup |
| 6 | Database client | Gerbil-Elixir protocol |
| 7 | Message manager | Message persistence |
| 8 | Message streaming | Streaming support |
| 9 | Memory blocks | Structured memory |
| 10 | Core memory ops | Memory tools |
| 11 | Archival memory | Long-term storage |
| 12 | Semantic search | Vector search |
| 13 | Core tools | Basic tools |
| 14 | Memory tools | Memory manipulation |
| 15 | Tool sandbox | Isolated execution |
| 16 | Tool rules | Execution constraints |
| 17 | Step execution | Agent loop |
| 18 | Context management | Auto-summarization |
| 19 | Streaming execution | Streaming loop |
| 20 | Performance | Optimization |
Month 1 (Weeks 1-4): LLM integration + HTTP server Month 2 (Weeks 5-8): Database + Message system Month 3 (Weeks 9-12): Advanced memory Month 4 (Weeks 13-16): Tool system Month 5 (Weeks 17-20): Execution loop
-
Setup Development Environment
cd /Users/liyuhang/work/o mkdir -p gerbil/llm gerbil/server gerbil/database gerbil/message gerbil/memory gerbil/tools -
Copy Gerbil Examples
cp ../gerbil_scheme_book/OpenAI_API_demo/openai.ss gerbil/llm/ cp ../gerbil_scheme_book/Anthropic_API_demo/anthropic.ss gerbil/llm/
-
Create Week 1 Branch
git checkout -b phase2-week1-llm-clients
-
Start Implementation
- Adapt OpenAI client
- Adapt Anthropic client
- Create unified types
- Write tests
- Each week delivers working functionality
- No big-bang integration
- Continuous testing
- Use Gerbil for everything possible
- Only use Zig/Rust for performance-critical operations
- Leverage gerbil_scheme_book examples
- Follow memos API design
- Use memos database schema
- Replicate memos functionality
- Write tests for everything
- Document as you go
- Refactor when needed
- Use Phase 0 & 1 foundation
- Adapt gerbil_scheme_book examples
- Extend Elixir supervision layer
This roadmap provides a clear, achievable path to building a memos-compatible agent in Gerbil Scheme.
Key Advantages:
- β Leverages existing Phase 0 & 1 work
- β Uses available Gerbil examples
- β Incremental weekly milestones
- β Clear success criteria
- β Realistic timeline (20 weeks)
Next Steps:
- Review and approve this roadmap
- Start Week 1 implementation
- Track progress weekly
- Adjust as needed
Estimated Completion: ~5 months from now Confidence: βββββ (5/5)
Let's build the future of AI agents in Gerbil Scheme! π