cognitive

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cognitive implements yaad's higher-level memory subsystems — epistemic state, curiosity, boundary detection, reconsolidation, and related processes layered on top of the core engine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoundaryStopWord

func BoundaryStopWord(w string) bool

func DetectOpenLoop

func DetectOpenLoop(text string, minLen int) string

func DetectResolution

func DetectResolution(text string) bool

Types

type BoundaryConfig

type BoundaryConfig struct {
	Enabled        bool    `json:"enabled"`
	WindowSize     int     `json:"window_size"`     // number of messages per comparison window
	ShiftThreshold float64 `json:"shift_threshold"` // minimum score to declare a boundary
	MinMessages    int     `json:"min_messages"`    // minimum messages before detection activates
}

BoundaryConfig holds configuration for semantic boundary detection.

func DefaultBoundaryConfig

func DefaultBoundaryConfig() BoundaryConfig

DefaultBoundaryConfig returns production-tuned defaults.

type BoundaryDetector

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

BoundaryDetector detects topic boundaries in a sequence of messages using lexical overlap analysis. When the vocabulary of a sliding window diverges sharply from the preceding window, a topic boundary is declared.

func NewBoundaryDetector

func NewBoundaryDetector(config BoundaryConfig) *BoundaryDetector

NewBoundaryDetector creates a boundary detector with the given config.

func (*BoundaryDetector) DetectBoundaries

func (bd *BoundaryDetector) DetectBoundaries(messages []string) []TopicBoundary

DetectBoundaries scans a slice of message texts and returns detected topic boundaries. Each boundary indicates a position where the conversation shifted to a new topic.

func (*BoundaryDetector) SegmentByBoundaries

func (bd *BoundaryDetector) SegmentByBoundaries(messages []string) [][]string

SegmentByBoundaries splits messages into segments based on detected boundaries. Each segment represents a coherent topic segment suitable for memory chunking.

type CuriosityConfig

type CuriosityConfig struct {
	Enabled    bool `json:"enabled"`
	MaxTargets int  `json:"max_targets"`
}

func DefaultCuriosityConfig

func DefaultCuriosityConfig() CuriosityConfig

type CuriosityEngine

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

func NewCuriosityEngine

func NewCuriosityEngine(config CuriosityConfig) *CuriosityEngine

func (*CuriosityEngine) AddTarget

func (e *CuriosityEngine) AddTarget(topic, gapType string, priority float64) *ExplorationTarget

func (*CuriosityEngine) GetTopTargets

func (e *CuriosityEngine) GetTopTargets(limit int) []*ExplorationTarget

func (*CuriosityEngine) MarkExplored

func (e *CuriosityEngine) MarkExplored(targetID, findings string) bool

type DirectiveType

type DirectiveType string
const (
	DirectiveContradiction DirectiveType = "contradiction"
	DirectiveKnowledgeGap  DirectiveType = "knowledge_gap"
	DirectiveLowConfidence DirectiveType = "low_confidence"
	DirectiveStaleFact     DirectiveType = "stale_fact"
)

type EpistemicConfig

type EpistemicConfig struct {
	Enabled             bool    `json:"enabled"`
	MaxActiveDirectives int     `json:"max_active_directives"`
	MaxPerSession       int     `json:"max_per_session"`
	MinPriority         float64 `json:"min_priority"`
	ExpiryDays          int     `json:"expiry_days"`
}

func DefaultEpistemicConfig

func DefaultEpistemicConfig() EpistemicConfig

type EpistemicDirective

type EpistemicDirective struct {
	ID              string        `json:"id"`
	Type            DirectiveType `json:"type"`
	Question        string        `json:"question"`
	Context         string        `json:"context"`
	Priority        float64       `json:"priority"`
	CreatedAt       time.Time     `json:"created_at"`
	ResolvedAt      *time.Time    `json:"resolved_at,omitempty"`
	Resolution      string        `json:"resolution,omitempty"`
	SourceEntityIDs []string      `json:"source_entity_ids"`
	Attempts        int           `json:"attempts"`
}

type EpistemicEngine

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

func NewEpistemicEngine

func NewEpistemicEngine(config EpistemicConfig) *EpistemicEngine

func (*EpistemicEngine) CreateDirective

func (e *EpistemicEngine) CreateDirective(dtype DirectiveType, question, context string, priority float64, sourceEntityIDs []string) *EpistemicDirective

func (*EpistemicEngine) ExpireOld

func (e *EpistemicEngine) ExpireOld() int

func (*EpistemicEngine) GetForSession

func (e *EpistemicEngine) GetForSession() []*EpistemicDirective

func (*EpistemicEngine) Resolve

func (e *EpistemicEngine) Resolve(directiveID, resolution string) bool

type ExplorationTarget

type ExplorationTarget struct {
	ID         string     `json:"id"`
	Topic      string     `json:"topic"`
	GapType    string     `json:"gap_type"`
	Priority   float64    `json:"priority"`
	CreatedAt  time.Time  `json:"created_at"`
	ExploredAt *time.Time `json:"explored_at,omitempty"`
	Findings   string     `json:"findings,omitempty"`
}

type LabileMemory

type LabileMemory struct {
	ChunkID      string    `json:"chunk_id"`
	RecalledAt   time.Time `json:"recalled_at"`
	Strengthened bool      `json:"strengthened"`
	Contradicted bool      `json:"contradicted"`
}

type OpenLoop

type OpenLoop struct {
	ChunkID    string    `json:"chunk_id"`
	Context    string    `json:"context"`
	DetectedAt time.Time `json:"detected_at"`
	Resolved   bool      `json:"resolved"`
}

type ProceduralConfig

type ProceduralConfig struct {
	Enabled         bool    `json:"enabled"`
	MaxPatterns     int     `json:"max_patterns"`
	MinFrequency    int     `json:"min_frequency"`
	SequenceMinLen  int     `json:"sequence_min_len"`
	SequenceMaxLen  int     `json:"sequence_max_len"`
	SimilarityThres float64 `json:"similarity_thres"`
}

ProceduralConfig holds configuration for the procedural memory engine.

func DefaultProceduralConfig

func DefaultProceduralConfig() ProceduralConfig

DefaultProceduralConfig returns production-tuned defaults.

type ProceduralEngine

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

ProceduralEngine tracks and learns workflow patterns from tool-use sequences.

func NewProceduralEngine

func NewProceduralEngine(config ProceduralConfig) *ProceduralEngine

NewProceduralEngine creates a new procedural memory engine.

func (*ProceduralEngine) Cleanup

func (e *ProceduralEngine) Cleanup() int

Cleanup removes patterns below the minimum frequency threshold.

func (*ProceduralEngine) GetPatterns

func (e *ProceduralEngine) GetPatterns(limit int) []*ProceduralMemory

GetPatterns returns all procedural patterns, sorted by frequency.

func (*ProceduralEngine) ObserveSequence

func (e *ProceduralEngine) ObserveSequence(tools []string, trigger string, success bool) *ProceduralMemory

ObserveSequence records a full observed tool sequence as a procedural memory. Called by session-end hooks when a meaningful sequence is detected.

func (*ProceduralEngine) RecordStep

func (e *ProceduralEngine) RecordStep(toolName string)

RecordStep appends a tool invocation step to the current session's sequence buffer. When the sequence reaches SequenceMaxLen or a session boundary is detected, the engine attempts to match the sequence against known patterns and either increments an existing pattern's frequency or creates a new one.

func (*ProceduralEngine) SuggestSteps

func (e *ProceduralEngine) SuggestSteps(prefix []string, limit int) []string

SuggestSteps returns the most likely next steps given a prefix of tool names. Returns nil if no matching pattern is found or the engine is disabled.

type ProceduralMemory

type ProceduralMemory struct {
	ID           string    `json:"id"`
	Name         string    `json:"name"`
	Description  string    `json:"description"`
	TriggerText  string    `json:"trigger_text"`
	StepSequence []string  `json:"step_sequence"`
	Tools        []string  `json:"tools"`
	Frequency    int       `json:"frequency"`
	SuccessRate  float64   `json:"success_rate"`
	CreatedAt    time.Time `json:"created_at"`
	LastUsedAt   time.Time `json:"last_used_at"`
	Tags         string    `json:"tags,omitempty"`
}

ProceduralMemory represents a learned workflow pattern extracted from observed tool-use sequences. Unlike explicit Skill nodes (which are user-defined step lists), procedural memories are inferred automatically from repeated trigger-action sequences in agent sessions.

type ProspectiveConfig

type ProspectiveConfig struct {
	Enabled          bool          `json:"enabled"`
	TriggerThreshold float64       `json:"trigger_threshold"`
	DefaultTTL       time.Duration `json:"default_ttl"`
	MaxActive        int           `json:"max_active"`
}

func DefaultProspectiveConfig

func DefaultProspectiveConfig() ProspectiveConfig

type ProspectiveEngine

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

func NewProspectiveEngine

func NewProspectiveEngine(config ProspectiveConfig) *ProspectiveEngine

func (*ProspectiveEngine) CheckTriggers

func (e *ProspectiveEngine) CheckTriggers(messageText string, messageEmbedding []float32) []*ProspectiveMemory

func (*ProspectiveEngine) CleanExpired

func (e *ProspectiveEngine) CleanExpired() int

func (*ProspectiveEngine) Create

func (e *ProspectiveEngine) Create(triggerCondition, action, sourceSession string, triggerEmbedding []float32, priority float64) *ProspectiveMemory

func (*ProspectiveEngine) GetActive

func (e *ProspectiveEngine) GetActive() []*ProspectiveMemory

type ProspectiveMemory

type ProspectiveMemory struct {
	ID               string     `json:"id"`
	TriggerCondition string     `json:"trigger_condition"`
	TriggerEmbedding []float32  `json:"trigger_embedding,omitempty"`
	Action           string     `json:"action"`
	CreatedAt        time.Time  `json:"created_at"`
	ExpiresAt        *time.Time `json:"expires_at,omitempty"`
	TriggeredAt      *time.Time `json:"triggered_at,omitempty"`
	SourceSession    string     `json:"source_session,omitempty"`
	Priority         float64    `json:"priority"`
}

type ReconsolidationConfig

type ReconsolidationConfig struct {
	Enabled       bool          `json:"enabled"`
	LabileWindow  time.Duration `json:"labile_window"`
	StrengthBonus float64       `json:"strength_bonus"`
}

func DefaultReconsolidationConfig

func DefaultReconsolidationConfig() ReconsolidationConfig

type ReconsolidationEngine

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

func NewReconsolidationEngine

func NewReconsolidationEngine(config ReconsolidationConfig) *ReconsolidationEngine

func (*ReconsolidationEngine) Cleanup

func (e *ReconsolidationEngine) Cleanup() int

func (*ReconsolidationEngine) FlagContradiction

func (e *ReconsolidationEngine) FlagContradiction(chunkID string)

func (*ReconsolidationEngine) GetContradicted

func (e *ReconsolidationEngine) GetContradicted() []string

func (*ReconsolidationEngine) IsLabile

func (e *ReconsolidationEngine) IsLabile(chunkID string) bool

func (*ReconsolidationEngine) OnRecall

func (e *ReconsolidationEngine) OnRecall(chunkID string)

func (*ReconsolidationEngine) Strengthen

func (e *ReconsolidationEngine) Strengthen(chunkID string) float64

type SomaticConfig

type SomaticConfig struct {
	Enabled        bool    `json:"enabled"`
	SkipThreshold  float64 `json:"skip_threshold"`
	BoostThreshold float64 `json:"boost_threshold"`
}

func DefaultSomaticConfig

func DefaultSomaticConfig() SomaticConfig

type SomaticEngine

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

func NewSomaticEngine

func NewSomaticEngine(config SomaticConfig) *SomaticEngine

func (*SomaticEngine) GetMarker

func (e *SomaticEngine) GetMarker(region string) *SomaticMarker

func (*SomaticEngine) RecordOutcome

func (e *SomaticEngine) RecordOutcome(region string, success bool)

func (*SomaticEngine) ShouldBoost

func (e *SomaticEngine) ShouldBoost(region string) bool

func (*SomaticEngine) ShouldSkip

func (e *SomaticEngine) ShouldSkip(region string) bool

type SomaticMarker

type SomaticMarker struct {
	Region     string  `json:"region"`
	Valence    float64 `json:"valence"`
	Arousal    float64 `json:"arousal"`
	Confidence float64 `json:"confidence"`
	Accesses   int     `json:"accesses"`
}

type TopicBoundary

type TopicBoundary struct {
	Position    int       `json:"position"`     // message index where the shift occurs
	Score       float64   `json:"score"`        // confidence of the boundary (0.0-1.0)
	BeforeTopic string    `json:"before_topic"` // inferred topic before the boundary
	AfterTopic  string    `json:"after_topic"`  // inferred topic after the boundary
	DetectedAt  time.Time `json:"detected_at"`
}

TopicBoundary represents a detected shift in conversation topic.

type ZeigarnikChunk

type ZeigarnikChunk struct {
	ID   string
	Text string
}

type ZeigarnikConfig

type ZeigarnikConfig struct {
	Enabled         bool    `json:"enabled"`
	DecayResistance float64 `json:"decay_resistance"`
	MinTextLength   int     `json:"min_text_length"`
}

func DefaultZeigarnikConfig

func DefaultZeigarnikConfig() ZeigarnikConfig

type ZeigarnikEngine

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

func NewZeigarnikEngine

func NewZeigarnikEngine(config ZeigarnikConfig) *ZeigarnikEngine

func (*ZeigarnikEngine) CloseLoop

func (e *ZeigarnikEngine) CloseLoop(chunkID string)

func (*ZeigarnikEngine) DecayMultiplier

func (e *ZeigarnikEngine) DecayMultiplier(chunkID string) float64

func (*ZeigarnikEngine) GetActiveLoops

func (e *ZeigarnikEngine) GetActiveLoops(limit int) []*OpenLoop

func (*ZeigarnikEngine) MarkOpenLoop

func (e *ZeigarnikEngine) MarkOpenLoop(chunkID, context string)

func (*ZeigarnikEngine) ScanChunks

func (e *ZeigarnikEngine) ScanChunks(chunks []ZeigarnikChunk) int

Jump to

Keyboard shortcuts

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