Documentation
¶
Overview ¶
Package learning provides LLM-based extraction of behavioral patterns from session transcripts.
Index ¶
Constants ¶
const ( // DefaultMaxMessages is the maximum number of messages to include in LLM input. DefaultMaxMessages = 20 // DefaultMaxMessageLen is the maximum length of a single message. DefaultMaxMessageLen = 2000 )
Variables ¶
This section is empty.
Functions ¶
func FormatTranscriptForExtraction ¶
FormatTranscriptForExtraction builds the user prompt from sanitized messages.
Types ¶
type ExtractedLearning ¶
type ExtractedLearning struct {
Title string `json:"title"`
Narrative string `json:"narrative"`
Concepts []string `json:"concepts"`
Type string `json:"type"` // "guidance", "decision", "bugfix", "discovery", etc.
Signal string `json:"signal"` // legacy: "correction", "preference", "pattern"
}
ExtractedLearning represents a single learning extracted by the LLM.
type ExtractionResult ¶
type ExtractionResult struct {
Learnings []ExtractedLearning `json:"learnings"`
}
ExtractionResult is the LLM response structure.
type Extractor ¶
type Extractor struct {
// contains filtered or unexported fields
}
Extractor handles LLM-based extraction of behavioral patterns from transcripts.
func NewExtractor ¶
NewExtractor creates a new learning extractor.
func (*Extractor) ExtractGuidance ¶
func (e *Extractor) ExtractGuidance(ctx context.Context, messages []Message, project string) ([]*models.ParsedObservation, error)
ExtractGuidance analyzes a session transcript and returns guidance observations.
type LLMClient ¶
type LLMClient interface {
Complete(ctx context.Context, systemPrompt, userPrompt string) (string, error)
}
LLMClient defines the interface for LLM completion calls.
type Message ¶
type Message struct {
Role string `json:"role"` // "user" or "assistant"
Text string `json:"text"`
}
Message represents a transcript message for LLM processing.
func SanitizeTranscript ¶
SanitizeTranscript prepares transcript messages for LLM input. It strips potentially adversarial content, limits length, and keeps only recent messages.
type OpenAIClient ¶
type OpenAIClient struct {
// contains filtered or unexported fields
}
OpenAIClient implements LLMClient using an OpenAI-compatible API.
func NewOpenAIClient ¶
func NewOpenAIClient(cfg OpenAIConfig) *OpenAIClient
NewOpenAIClient creates a new OpenAI-compatible LLM client.
func (*OpenAIClient) Complete ¶
func (c *OpenAIClient) Complete(ctx context.Context, systemPrompt, userPrompt string) (string, error)
Complete sends a chat completion request and returns the response text.
func (*OpenAIClient) IsConfigured ¶
func (c *OpenAIClient) IsConfigured() bool
IsConfigured returns true if the LLM client has a URL configured.
type OpenAIConfig ¶
type OpenAIConfig struct {
BaseURL string // ENGRAM_LLM_URL (default: reuse ENGRAM_EMBEDDING_URL base)
APIKey string // ENGRAM_LLM_API_KEY
Model string // ENGRAM_LLM_MODEL (default: gpt-4o-mini)
MaxTokens int // ENGRAM_LLM_MAX_TOKENS (default: 4096)
Timeout time.Duration // HTTP client timeout (default: 120s)
}
OpenAIConfig holds configuration for the OpenAI-compatible client.
func DefaultOpenAIConfig ¶
func DefaultOpenAIConfig() OpenAIConfig
DefaultOpenAIConfig returns config from environment variables.