learning

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package learning provides LLM-based extraction of behavioral patterns from session transcripts.

Index

Constants

View Source
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

func FormatTranscriptForExtraction(messages []Message) string

FormatTranscriptForExtraction builds the user prompt from sanitized messages.

func IsEnabled

func IsEnabled() bool

IsEnabled returns true if learning extraction is enabled and configured.

Types

type ExtractedLearning

type ExtractedLearning struct {
	Title     string   `json:"title"`
	Narrative string   `json:"narrative"`
	Concepts  []string `json:"concepts"`
	Signal    string   `json:"signal"` // "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

func NewExtractor(llm LLMClient) *Extractor

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

func SanitizeTranscript(messages []Message, maxMessages, maxMsgLen int) []Message

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)
	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.

Jump to

Keyboard shortcuts

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