metacognitive

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: May 1, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package metacognitive implements a perpetual self-regulating attention loop that receives persistent state, reasons via LLM, and adapts its own sleep cycle. See issue #319.

Each iteration is a fresh conversation. State persists across iterations via a markdown file (metacognitive.md by default). The loop's cost is self-limiting: quiet periods produce long sleeps and few iterations.

"Dice" randomly select a frontier model for supervisor iterations that review the loop's own behavior, catching blind spots that the cheaper local model's consistent reasoning patterns miss.

The loop lifecycle is managed by the loop package. This package provides BuildLoopConfig to assemble a loop.Config with the correct TaskBuilder, PostIterate, and tool exclusions.

Index

Constants

View Source
const DefinitionName = "metacognitive"

DefinitionName is the durable loops-ng definition name for the metacognitive service.

Variables

This section is empty.

Functions

func BuildLoopConfig

func BuildLoopConfig(cfg Config, opts Opts) loop.Config

BuildLoopConfig returns the engine-facing loop.Config view of the metacognitive loop. Kept as a compatibility bridge while loops-ng adoption is in progress.

func BuildSpec

func BuildSpec(cfg Config, opts Opts) loop.Spec

BuildSpec returns a loop.Spec that implements the metacognitive loop as a standard loops-ng service. The returned spec declares the durable output document and uses runtime hooks to build prompts and append iteration logs.

func DefinitionSpec

func DefinitionSpec(cfg Config) loop.Spec

DefinitionSpec returns the persistable loops-ng definition for the metacognitive service. Runtime hooks are attached later by HydrateSpec so the definition can live in the durable registry.

func HydrateSpec

func HydrateSpec(spec loop.Spec, cfg Config, opts Opts) loop.Spec

HydrateSpec attaches the runtime-only hooks needed to execute the metacognitive service from a durable loops-ng definition.

Types

type Config

type Config struct {
	Enabled                bool
	StateFile              string // fixed filename under workspace/core
	MinSleep               time.Duration
	MaxSleep               time.Duration
	DefaultSleep           time.Duration
	Jitter                 float64 // 0.0–1.0
	SupervisorProbability  float64 // 0.0–1.0
	QualityFloor           int     // normal iterations
	SupervisorQualityFloor int     // supervisor iterations
}

Config holds the parsed metacognitive loop configuration with time.Duration fields (as opposed to the YAML string representation in config.MetacognitiveConfig).

func ParseConfig

func ParseConfig(raw config.MetacognitiveConfig) (Config, error)

ParseConfig converts a config.MetacognitiveConfig (string durations) into a Config (time.Duration fields). Call after config validation has passed.

type Opts

type Opts struct {
	// WorkspacePath is the absolute path to the workspace directory.
	// Used only as a fallback when ProvenanceStore is nil.
	WorkspacePath string

	// StateFilePath is the resolved absolute path to the state file.
	// When a provenance store is configured, this points inside the
	// store; otherwise it falls back to workspace-relative resolution.
	StateFilePath string

	// ProvenanceStore, when non-nil, is used by the iteration logger
	// to commit state file updates with SSH signatures.
	ProvenanceStore ProvenanceWriter

	// StateFileName is the bare filename (e.g. "metacognitive.md") used
	// for provenance store reads and writes. Ignored when ProvenanceStore
	// is nil.
	StateFileName string
}

Opts holds options for BuildLoopConfig that are not part of Config.

type ProvenanceWriter

type ProvenanceWriter interface {
	Read(filename string) (string, error)
	Write(ctx context.Context, filename, content, message string) error
}

ProvenanceWriter is the subset of [provenance.Store] needed by the metacognitive loop for committing state file updates.

Jump to

Keyboard shortcuts

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