plugins/hooks/reflection/reflection
Reflection hook — background memory consolidation. Fires after N user turns. Spawns a background process that replays the conversation with a restricted tool list (memory only) and asks the model to consolidate learnings into the memory store.
Best-effort: errors are logged, never surfaced to the user. The background process opens its own DB connection so it doesn’t share state with the main conversation loop.
Values
pub fn reflection_hook(
log: behaviours.Logger,
db_connector: behaviours.DbConnector,
db_path: String,
) -> behaviours.ReflectionHook
pub fn should_reflect(
turn_count: Int,
turn_interval: Int,
) -> Bool
Check whether Reflection should fire based on the current turn count.
pub fn spawn_review(
client: client.Client,
persona: String,
history: List(message.Message),
user_key: String,
make_memory_tool: fn(sqlight.Connection, String) -> tool.Tool,
log: behaviours.Logger,
db_connector: behaviours.DbConnector,
db_path: String,
) -> Nil
Spawn a background process that reviews the conversation and consolidates
memories. Returns immediately — the review runs asynchronously.
make_memory_tool creates a memory tool given a fresh DB connection,
so the background review doesn’t share state with the main loop.