Skip to content

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

BehaviourOne-line description
LLMClientSends conversation messages to the LLM API and classifies errors (retryable, compressible)
SessionStoreFull CRUD for sessions: create, load, append messages, list, search, prune, export
MemoryStorePersistent user memory: add, get, replace, remove entries; format for system prompt
GuardrailPre-execution safety check on tool commands; classifies risk and caches approvals
LoggerStructured logging with four levels (debug, info, warn, error) across eight categories
ContextBuilderAssembles system prompt and tool continuation messages for the conversation context
TokenEstimatorEstimates token counts for request payloads; computes context window usage percentage
CompressorHookPreemptive conversation compression: split history, build summary, apply compression with cooldown
GuardrailHookTool loop guardrails: tracks success/failure to detect repetition and stuck loops
ReflectionHookPost-turn reflection: decides when to spawn an async review agent that consolidates memories
DndCheckerDo-not-disturb scheduling: checks quiet periods, manages DND rules
CronStoreCron job persistence: list, upsert, delete, touch cron job rows
DbConnectorSQLite lifecycle: open, close, checkpoint, integrity check, run migrations

Supporting Types

  • PruneResult -- returned by SessionStore.prune_sessions, contains deleted_count and orphaned_count
  • DndRule -- do-not-disturb rule with id, rule_type, start_time, end_time, enabled, created_at
  • 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

Built with Gleam on the BEAM/Erlang VM.