conversation

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyContent       = errors.New("message content cannot be empty")
	ErrInvalidRole        = errors.New("invalid message role")
	ErrThreadNotFound     = errors.New("thread not found")
	ErrNothingToSummarize = errors.New("not enough messages to summarize")
	ErrSummarizerNotSet   = errors.New("summarizer not configured")
)

Common errors returned by the conversation engine.

View Source
var ValidRoles = map[string]bool{
	"user":      true,
	"assistant": true,
	"system":    true,
	"tool":      true,
}

ValidRoles defines the allowed message roles.

Functions

This section is empty.

Types

type AppendOpts

type AppendOpts struct {
	MaxContentLength int               // Truncate content if exceeds this (0 = no truncation)
	Metadata         map[string]string // Optional metadata
	SkipEmbedding    bool              // Skip embedding generation even if enabled
}

AppendOpts contains options for appending a message.

type Engine

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

Engine implements the conversation memory logic layer. It orchestrates storage and embedding operations for conversation management.

func NewEngine

func NewEngine(store storage.Backend, emb embedding.Provider, cfg *config.ConversationConfig) (*Engine, error)

NewEngine creates a new conversation engine. The embedding provider can be nil if semantic search is disabled. The summarizer can be nil if summarization is not needed.

func (*Engine) Append

func (e *Engine) Append(ctx context.Context, namespace, threadID, role, content string, opts *AppendOpts) (*types.Message, error)

Append adds a message to a conversation thread. Creates the thread if it doesn't exist. Generates embedding if semantic search is enabled.

func (*Engine) Clear

func (e *Engine) Clear(ctx context.Context, namespace, threadID string) error

Clear deletes all messages in a thread and the thread itself.

func (*Engine) GetThread

func (e *Engine) GetThread(ctx context.Context, namespace, threadID string) (*types.Thread, error)

GetThread retrieves a single thread by ID.

func (*Engine) History

func (e *Engine) History(ctx context.Context, namespace, threadID string, opts *HistoryOpts) (*HistoryResult, error)

History retrieves conversation history for a thread. Returns messages in chronological order (oldest first). Auto-triggers summarization if message count exceeds threshold.

func (*Engine) ListThreads

func (e *Engine) ListThreads(ctx context.Context, namespace string, cursor string, limit int) ([]*types.Thread, string, error)

ListThreads returns all threads in a namespace.

func (*Engine) MarkSummarized

func (e *Engine) MarkSummarized(ctx context.Context, namespace, threadID string, beforeTime time.Time) error

MarkSummarized marks messages as having been included in a summary. This is used after summarization to track which messages were summarized.

func (*Engine) Search

func (e *Engine) Search(ctx context.Context, namespace, query string, opts *SearchOpts) (*SearchResult, error)

Search performs semantic search across messages in a namespace. Requires semantic search to be enabled and embedding provider configured. Supports vector (default), hybrid, or text search modes.

func (*Engine) SetExtractionEnqueuer

func (e *Engine) SetExtractionEnqueuer(eq ExtractionEnqueuer)

SetExtractionEnqueuer sets the extraction enqueuer for entity extraction. When set, messages will be queued for background entity extraction.

func (*Engine) SetSummarizer

func (e *Engine) SetSummarizer(s Summarizer)

SetSummarizer sets the summarizer for conversation summarization. This is optional and can be called after engine creation.

func (*Engine) ShouldSummarize

func (e *Engine) ShouldSummarize(ctx context.Context, namespace, threadID string) (bool, error)

ShouldSummarize checks if a thread should be auto-summarized based on message count.

func (*Engine) Summarize

func (e *Engine) Summarize(ctx context.Context, namespace, threadID string, opts *SummarizeOpts) (*SummarizeResult, error)

Summarize compresses older messages into a summary via LLM. The summary is stored in the thread record and older messages are marked as summarized. Recent messages (controlled by KeepRecent) are left unsummarized.

func (*Engine) UpdateThread

func (e *Engine) UpdateThread(ctx context.Context, thread *types.Thread) error

UpdateThread updates a thread's metadata (title, summary).

type ExtractionEnqueuer

type ExtractionEnqueuer interface {
	EnqueueForExtraction(ctx context.Context, namespace, sourceType, sourceID, content string) error
}

ExtractionEnqueuer queues content for entity extraction.

type HistoryOpts

type HistoryOpts struct {
	LastN             int    // Number of recent messages to retrieve (0 = use default)
	IncludeSummary    bool   // Prepend thread summary if available
	Cursor            string // Pagination cursor
	SkipAutoSummarize bool   // Skip auto-summarization check (internal use)
}

HistoryOpts contains options for retrieving conversation history.

type HistoryResult

type HistoryResult struct {
	Messages   []*types.Message `json:"messages"`
	Summary    string           `json:"summary,omitempty"`
	NextCursor string           `json:"next_cursor,omitempty"`
	ThreadID   string           `json:"thread_id"`
}

HistoryResult contains the result of a history query.

type SearchMode

type SearchMode string

SearchMode defines the type of search to perform.

const (
	SearchModeVector SearchMode = "vector" // Vector similarity search only
	SearchModeHybrid SearchMode = "hybrid" // Combined vector + full-text search (RRF)
	SearchModeText   SearchMode = "text"   // Full-text search only (falls back to vector if unavailable)
)

type SearchOpts

type SearchOpts struct {
	ThreadID   *string    // Optional: limit search to specific thread
	TopK       int        // Number of results (0 = default 10)
	MinScore   float64    // Minimum similarity score (0-1)
	SearchMode SearchMode // Search mode: "vector" (default), "hybrid", or "text"
	Alpha      float64    // Hybrid search weight (0=pure text, 1=pure vector, 0.5=equal)
}

SearchOpts contains options for semantic search.

type SearchResult

type SearchResult struct {
	Results []*types.MessageResult `json:"results"`
	Query   string                 `json:"query"`
}

SearchResult contains search results.

type SummarizeOpts

type SummarizeOpts struct {
	KeepRecent int // Number of recent messages to keep unsummarized (default: 10)
}

SummarizeOpts contains options for summarization.

type SummarizeResult

type SummarizeResult struct {
	Summary            string `json:"summary"`
	MessagesSummarized int    `json:"messages_summarized"`
	MessagesKept       int    `json:"messages_kept"`
	ThreadID           string `json:"thread_id"`
}

SummarizeResult contains the result of summarization.

type Summarizer

type Summarizer interface {
	SummarizeMessages(ctx context.Context, messages []*types.Message) (string, error)
}

Summarizer generates summaries from conversation messages.

Jump to

Keyboard shortcuts

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