learning

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalysisBuffer

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

AnalysisBuffer manages async conversation analysis processing.

func NewAnalysisBuffer

func NewAnalysisBuffer(
	analyzer *ConversationAnalyzer,
	learner *SessionLearner,
	getMessages MessageProvider,
	turnThreshold, tokenThreshold int,
	logger *zap.SugaredLogger,
) *AnalysisBuffer

NewAnalysisBuffer creates a new async analysis buffer.

func (*AnalysisBuffer) Start

func (b *AnalysisBuffer) Start(wg *sync.WaitGroup)

Start launches the background analysis goroutine.

func (*AnalysisBuffer) Stop

func (b *AnalysisBuffer) Stop()

Stop signals the background goroutine to drain and exit.

func (*AnalysisBuffer) Trigger

func (b *AnalysisBuffer) Trigger(sessionKey string)

Trigger checks if analysis is needed for a session and enqueues if thresholds are met.

func (*AnalysisBuffer) TriggerSessionEnd

func (b *AnalysisBuffer) TriggerSessionEnd(sessionKey string)

TriggerSessionEnd enqueues a session-end analysis request.

type AnalysisRequest

type AnalysisRequest struct {
	SessionKey string
	SessionEnd bool // true for session-end analysis
}

AnalysisRequest represents a request to analyze a session's conversation.

type ConversationAnalyzer

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

ConversationAnalyzer extracts knowledge from conversation turns using LLM analysis.

func NewConversationAnalyzer

func NewConversationAnalyzer(
	generator TextGenerator,
	store *knowledge.Store,
	logger *zap.SugaredLogger,
) *ConversationAnalyzer

NewConversationAnalyzer creates a new conversation analyzer.

func (*ConversationAnalyzer) Analyze

func (a *ConversationAnalyzer) Analyze(ctx context.Context, sessionKey string, messages []session.Message) error

Analyze processes a batch of messages and extracts knowledge.

func (*ConversationAnalyzer) SetGraphCallback

func (a *ConversationAnalyzer) SetGraphCallback(cb GraphCallback)

SetGraphCallback sets the optional graph update hook.

type Engine

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

Engine observes tool execution results and learns from errors.

func NewEngine

func NewEngine(store *knowledge.Store, logger *zap.SugaredLogger) *Engine

NewEngine creates a new learning engine.

func (*Engine) GetFixForError

func (e *Engine) GetFixForError(ctx context.Context, toolName string, err error) (string, bool)

GetFixForError returns a known fix for a given tool error if one exists with sufficient confidence.

func (*Engine) OnToolResult

func (e *Engine) OnToolResult(ctx context.Context, sessionKey, toolName string, params map[string]interface{}, result interface{}, err error)

OnToolResult observes a tool execution result and records learnings.

func (*Engine) RecordUserCorrection

func (e *Engine) RecordUserCorrection(ctx context.Context, sessionKey, trigger, diagnosis, fix string) error

RecordUserCorrection saves a user-provided correction as a high-confidence learning.

type GraphCallback

type GraphCallback func(triples []graph.Triple)

GraphCallback is a hook for asynchronous graph updates from the learning system.

type GraphEngine

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

GraphEngine extends the learning engine with graph-based relationship tracking and confidence propagation across similar learnings.

func NewGraphEngine

func NewGraphEngine(store *knowledge.Store, graphStore graph.Store, logger *zap.SugaredLogger) *GraphEngine

NewGraphEngine creates a graph-enhanced learning engine.

func (*GraphEngine) OnToolResult

func (e *GraphEngine) OnToolResult(ctx context.Context, sessionKey, toolName string, params map[string]interface{}, result interface{}, err error)

OnToolResult observes a tool execution result, records learnings, and updates the knowledge graph with error-resolution relationships.

func (*GraphEngine) RecordFix

func (e *GraphEngine) RecordFix(ctx context.Context, errorPattern, fix, sessionKey string)

RecordFix records an error-fix relationship in the graph.

func (*GraphEngine) SetGraphCallback

func (e *GraphEngine) SetGraphCallback(cb GraphCallback)

SetGraphCallback sets the asynchronous graph update hook.

type MessageProvider

type MessageProvider func(sessionKey string) ([]session.Message, error)

MessageProvider retrieves messages for a session key.

type SessionLearner

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

SessionLearner extracts high-confidence knowledge at session end.

func NewSessionLearner

func NewSessionLearner(
	generator TextGenerator,
	store *knowledge.Store,
	logger *zap.SugaredLogger,
) *SessionLearner

NewSessionLearner creates a new session learner.

func (*SessionLearner) LearnFromSession

func (l *SessionLearner) LearnFromSession(ctx context.Context, sessionKey string, messages []session.Message) error

LearnFromSession analyzes a complete session and stores high-confidence results.

func (*SessionLearner) SetGraphCallback

func (l *SessionLearner) SetGraphCallback(cb GraphCallback)

SetGraphCallback sets the optional graph update hook.

type TextGenerator

type TextGenerator interface {
	GenerateText(ctx context.Context, systemPrompt, userPrompt string) (string, error)
}

TextGenerator generates text from a prompt (mirrors memory.TextGenerator to avoid import cycle).

type ToolResultObserver

type ToolResultObserver interface {
	OnToolResult(ctx context.Context, sessionKey, toolName string, params map[string]interface{}, result interface{}, err error)
}

ToolResultObserver observes tool execution results for learning. Both Engine and GraphEngine implement this interface.

Jump to

Keyboard shortcuts

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