reflection

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 13, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package reflection implements the Engram Reflection Engine v1.

The Reflection Engine periodically synthesizes high-level insights from unreflected memories, inspired by the Generative Agents paper. It runs lighter and more frequently than the Dream Engine (1-3x/day vs 1x/day), and focuses on cross-domain pattern discovery rather than same-tag dedup.

Trigger: accumulated importance of unreflected memories >= threshold (default: 50). Min interval: 2h. Max per day: 3 runs.

Output: TypeInsight memories with source="system", tagged with metadata.reflection_source_ids and metadata.reflected=true on source memories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CheckResult

type CheckResult struct {
	ShouldTrigger         bool    `json:"should_trigger"`
	SkipReason            string  `json:"skip_reason,omitempty"`
	UnreflectedCount      int     `json:"unreflected_count"`
	AccumulatedImportance float64 `json:"accumulated_importance"`
	Threshold             float64 `json:"threshold"`
	HoursSinceLastRun     float64 `json:"hours_since_last_run"`
	RunsToday             int     `json:"runs_today"`
}

CheckResult is the output of a trigger check.

type Config

type Config struct {
	// Threshold is the cumulative importance of unreflected memories required
	// to trigger a reflection run. Default: 50.
	Threshold float64

	// MaxInputSize is the maximum number of memories to feed into one reflection
	// cycle. Default: 20.
	MaxInputSize int

	// MinIntervalH is the minimum hours between reflection runs. Default: 2.
	MinIntervalH float64

	// DryRun disables all writes (no new insights, no marking as reflected).
	DryRun bool
}

Config holds Reflection Engine runtime configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default Reflection Engine configuration.

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine orchestrates the reflection cycle.

func NewEngine

func NewEngine(store memory.Store, embedder embedding.Embedder, cfg Config) *Engine

NewEngine creates a new Reflection Engine instance.

func (*Engine) Check

func (e *Engine) Check(ctx context.Context) (*CheckResult, error)

Check evaluates whether reflection should run now without executing it. Returns a CheckResult with should_trigger, skip_reason, and metrics.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context) (*RunResult, error)

Run executes one reflection cycle. Respects DryRun mode. Returns RunResult with metrics on what was done.

type ParsedInsight

type ParsedInsight struct {
	Content    string
	Importance float64
	Tags       []string
}

ParsedInsight holds a single parsed insight from Haiku's response.

type RunResult

type RunResult struct {
	Triggered         bool     `json:"triggered"`
	SkipReason        string   `json:"skip_reason,omitempty"`
	InputCount        int      `json:"input_count"`
	InsightsCreated   int      `json:"insights_created"`
	SourcesMarked     int      `json:"sources_marked"`
	Duration          string   `json:"duration"`
	TriggerImportance float64  `json:"trigger_importance,omitempty"`
	DryRun            bool     `json:"dry_run"`
	Errors            []string `json:"errors,omitempty"`
}

RunResult holds the output of a single reflection run.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL