Documentation
¶
Overview ¶
Package learning provides self-learning from tool execution results.
Engine analyzes tool execution outcomes to extract reusable patterns, categorizes errors (Timeout, Permission, Provider, Tool, General), and persists learnings to the knowledge store and agent memory.
GraphEngine extends Engine with graph triple generation and confidence propagation. ConversationAnalyzer and SessionLearner analyze conversation history for deeper pattern extraction. AnalysisBuffer batches analysis with turn/token thresholds.
Related packages:
- knowledge: primary store where learnings are persisted
- agentmemory: per-agent memory where patterns are stored
- memory: observational memory (source of conversation data)
- graph: triple store updated with extracted relationships
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 ¶
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 llm.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) SetEventBus ¶ added in v0.7.0
func (a *ConversationAnalyzer) SetEventBus(bus *eventbus.Bus)
SetEventBus sets the optional event bus for publishing triple events.
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 ¶
GetFixForError returns a known fix for a given tool error if one exists with sufficient confidence.
type GraphCallback ¶
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) SetEventBus ¶ added in v0.7.0
func (e *GraphEngine) SetEventBus(bus *eventbus.Bus)
SetEventBus sets the optional event bus for publishing triple events.
type MessageProvider ¶
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 llm.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) SetEventBus ¶ added in v0.7.0
func (l *SessionLearner) SetEventBus(bus *eventbus.Bus)
SetEventBus sets the optional event bus for publishing triple events.
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.