Behaviours
Source: core/behaviours/behaviours.gleam
The behaviours file defines 13 behaviour record types -- structural contracts for dependency injection. Gleam has no traits or protocols, so records of function fields serve as contracts between layers. Core modules depend on these behaviour types, never on concrete service or plugin modules. This keeps core a pure wireframe with no I/O or external imports.
Each service or plugin module exports a constructor function that returns its behaviour record. The composition root (Blessed Violators) wires these constructors together at startup.
The 13 Behaviours
| Behaviour | One-line description |
|---|---|
LLMClient | Sends conversation messages to the LLM API and classifies errors (retryable, compressible) |
SessionStore | Full CRUD for sessions: create, load, append messages, list, search, prune, export |
MemoryStore | Persistent user memory: add, get, replace, remove entries; format for system prompt |
Guardrail | Pre-execution safety check on tool commands; classifies risk and caches approvals |
Logger | Structured logging with four levels (debug, info, warn, error) across eight categories |
ContextBuilder | Assembles system prompt and tool continuation messages for the conversation context |
TokenEstimator | Estimates token counts for request payloads; computes context window usage percentage |
CompressorHook | Preemptive conversation compression: split history, build summary, apply compression with cooldown |
GuardrailHook | Tool loop guardrails: tracks success/failure to detect repetition and stuck loops |
ReflectionHook | Post-turn reflection: decides when to spawn an async review agent that consolidates memories |
DndChecker | Do-not-disturb scheduling: checks quiet periods, manages DND rules |
CronStore | Cron job persistence: list, upsert, delete, touch cron job rows |
DbConnector | SQLite lifecycle: open, close, checkpoint, integrity check, run migrations |
Supporting Types
PruneResult-- returned bySessionStore.prune_sessions, containsdeleted_countandorphaned_countDndRule-- do-not-disturb rule withid,rule_type,start_time,end_time,enabled,created_at
Related Pages
- Dependency Injection -- How behaviours wire services and plugins into core
- Blessed Violators -- The composition root modules that construct behaviour records
- Config -- Configuration loader that drives behaviour wiring