ENยทESยทDEยทPTยทFR
โŒ˜K

State Management & Memory

SQLite-backed persistence with in-memory working memory, semantic search via embeddings, and tri-hybrid retrieval.

v0.9.x update
Canonical conversation persistence is now the events table. Legacy messages data is migrated into events during upgrade.

Database Schema

messages table

KeyTypeDefaultDescription
idTEXT PKโ€”UUID primary key
session_idTEXTโ€”Session identifier (indexed)
roleTEXTโ€”user, assistant, or tool
contentTEXTnullMessage text content
tool_call_idTEXTnullID for tool result messages
tool_nameTEXTnullTool name for tool messages
tool_calls_jsonTEXTnullJSON array of tool calls
created_atTEXTโ€”RFC3339 timestamp
importanceREAL0.5Importance score (0.0โ€“1.0)
embeddingBLOBnullJSON-encoded Vec<f32> embedding
embedding_errorTEXTnullError message if embedding failed
consolidated_atTEXTnullMemory consolidation timestamp

facts table

KeyTypeDefaultDescription
idINTEGER PKautoAuto-incrementing primary key
categoryTEXTโ€”Grouping category
keyTEXTโ€”Fact key (unique per category)
valueTEXTโ€”Fact content
sourceTEXT""Who stored it: "agent" or "user"
created_atTEXTโ€”RFC3339 timestamp
updated_atTEXTโ€”RFC3339 timestamp

macros table

KeyTypeDefaultDescription
idINTEGER PKautoAuto-incrementing primary key
trigger_toolTEXTTool that triggers the macro
trigger_args_patternTEXTnullArguments pattern to match
next_toolTEXTTool to chain next
next_argsTEXTArguments for the chained tool
confidenceREAL0.0Confidence score for the macro
used_countINTEGER0Number of times the macro has been used
created_atTEXTRFC3339 timestamp
updated_atTEXTRFC3339 timestamp

scheduled_tasks table

KeyTypeDefaultDescription
idTEXT PKโ€”UUID primary key
nameTEXTโ€”Human-readable task label
cron_exprTEXTโ€”Computed 5-field cron expression
original_scheduleTEXTโ€”User input (natural language or cron)
promptTEXTโ€”Agent prompt to execute on schedule
sourceTEXTโ€”"tool" (created via tool) or "config" (from config.toml)
is_oneshotINTEGER0Fire once then auto-delete
is_pausedINTEGER0Paused tasks do not fire
is_trustedINTEGER0Trusted tasks skip terminal approval
next_run_atTEXTโ€”RFC3339 timestamp of next scheduled run
last_run_atTEXTnullRFC3339 timestamp of last execution
created_atTEXTโ€”RFC3339 timestamp
updated_atTEXTโ€”RFC3339 timestamp

terminal_allowed_prefixes table

KeyTypeDefaultDescription
prefixTEXT PKโ€”Command prefix persisted from "Allow Always" approvals

Working Memory

An in-memory HashMap<String, VecDeque<Message>> per session, capped at working_memory_cap (default 50). Avoids database hits for recent conversation history.

Tri-Hybrid Retrieval

The get_context method combines three retrieval strategies:

StrategySourceLimitPurpose
RecencyLast N messages10Conversational continuity
Salienceimportance ≥ 0.85Critical flagged memories
RelevanceVector similarity > 0.655Semantic search via embeddings

Results are deduplicated by message ID before being included in context.

Embedding Service

  • Model: AllMiniLML6V2 (via fastembed)
  • Runs in background โ€” embeds new messages after they are appended
  • Enables the relevance leg of tri-hybrid retrieval

Memory Consolidation

A background task runs every consolidation_interval_hours (default 6). It compresses old conversations into summaries using the fast model, reducing storage and context window usage.

Importance Scoring

RoleDefault Score
User message0.5
Assistant response0.5
Tool output0.3
System message0.1

Connection Pool

  • SQLite pool: max 5 connections
  • Journal mode: WAL (Write-Ahead Logging) for concurrent reads
  • Auto-creates database and tables if missing