working

package
v0.0.0-...-0f11aa8 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHistoryHook

func NewHistoryHook(mem llm.History) llm.BeforeGenerateHook

NewHistoryHook returns a BeforeGenerateHook that reads the session history from the given History store and appends it to CurrentMessages.

Types

type DiskBacked

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

DiskBacked provides a persistence-backed implementation of the WorkingMemory interface. It loads historical sessions on instantiation and saves the state to disk upon every Append.

func NewDiskBacked

func NewDiskBacked(path string, processors ...Processor) (*DiskBacked, error)

NewDiskBacked initializes a new DiskBacked history repository loaded from the provided directory.

func (*DiskBacked) Append

func (db *DiskBacked) Append(ctx context.Context, sessionID string, msg llm.Message) error

Append adds a new message to the existing session history, runs processors, and writes the state to disk.

func (*DiskBacked) Read

func (db *DiskBacked) Read(ctx context.Context, sessionID string) ([]llm.Message, error)

Read retrieves the full message history for a given session.

func (*DiskBacked) Sessions

func (db *DiskBacked) Sessions() map[string][]llm.Message

Sessions returns a shallow copy of the state map for interrogation (e.g. CLI loading)

type InMemory

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

InMemory provides a naive, memory-backed implementation of the WorkingMemory interface.

func NewInMemory

func NewInMemory(processors ...Processor) *InMemory

NewInMemory initializes a new InMemory history repository.

func (*InMemory) Append

func (m *InMemory) Append(ctx context.Context, sessionID string, msg llm.Message) error

Append adds a new message to the existing session history and runs processors.

func (*InMemory) Read

func (m *InMemory) Read(ctx context.Context, sessionID string) ([]llm.Message, error)

Read retrieves the full message history for a given session.

type Processor

type Processor interface {
	Process(ctx context.Context, sessionID string, msgs []llm.Message) ([]llm.Message, error)
}

Processor inspects, mutates, or summarizes a slice of working memory. Processors can be chained together.

func NewTruncationCompactor

func NewTruncationCompactor(maxMessages int) Processor

NewTruncationCompactor creates a basic compactor that ensures the history size (number of messages) never exceeds maxMessages. If it is exceeded, it preserves the newest messages up to the limit.

type ProcessorFunc

type ProcessorFunc func(ctx context.Context, sessionID string, msgs []llm.Message) ([]llm.Message, error)

ProcessorFunc allows simple functions to satisfy the Processor interface

func (ProcessorFunc) Process

func (p ProcessorFunc) Process(ctx context.Context, sessionID string, msgs []llm.Message) ([]llm.Message, error)

type WorkingMemory

type WorkingMemory interface {
	llm.History
}

WorkingMemory encapsulates context-window management for LLM sessions.

Jump to

Keyboard shortcuts

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