autodream

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package autodream provides context consolidation for M31A sessions. When conversation context grows large, AutoDream summarizes older messages into a single memory segment to stay within the model's context window.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyConsolidating = fmt.Errorf("autodream consolidation already in progress")

ErrAlreadyConsolidating is returned when a consolidation is already in progress (M-7 reentrancy guard).

Functions

This section is empty.

Types

type ConsolidationResult

type ConsolidationResult struct {
	Success         bool   `json:"success"`
	MessagesRemoved int    `json:"messages_removed"`
	TokensSaved     int    `json:"tokens_saved"`
	DurationMs      int64  `json:"duration_ms"`
	Summary         string `json:"summary"`
	Error           string `json:"error,omitempty"`
}

ConsolidationResult reports the outcome of a Consolidate() call.

type Consolidator

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

Consolidator manages context consolidation for a session. It holds a snapshot of the message history and provides thread-safe methods to consolidate (summarize the oldest 50% of non-protected messages), pause, resume, and report statistics.

func New

func New(messages []types.Message) *Consolidator

New creates a Consolidator that owns a defensive copy of the given messages.

func NewWithEstimator added in v1.3.0

func NewWithEstimator(messages []types.Message, est *tokens.Estimator) *Consolidator

NewWithEstimator creates a Consolidator with an accurate token estimator. When provided, token counts use the real tokenizer instead of word-count heuristics.

func (*Consolidator) CanConsolidate

func (c *Consolidator) CanConsolidate() bool

CanConsolidate returns true if a consolidation can be performed.

func (*Consolidator) Consolidate

func (c *Consolidator) Consolidate() *ConsolidationResult

Consolidate compacts the oldest 50% of non-protected messages into a single memory segment. Protected messages (first message, system messages, tool call messages, and the last 5 messages) are never consolidated. Returns ErrAlreadyConsolidating if a consolidation is already in progress (M-7).

func (*Consolidator) IsPaused

func (c *Consolidator) IsPaused() bool

IsPaused returns true if consolidation is paused.

func (*Consolidator) Messages

func (c *Consolidator) Messages() []types.Message

Messages returns a defensive copy of the managed message slice. Mutating the returned slice does not affect the Consolidator's internal state.

func (*Consolidator) Pause

func (c *Consolidator) Pause()

Pause prevents consolidation from happening. CanConsolidate will return false.

func (*Consolidator) Resume

func (c *Consolidator) Resume()

Resume re-enables consolidation.

func (*Consolidator) SetMessages

func (c *Consolidator) SetMessages(messages []types.Message)

SetMessages replaces the Consolidator's internal message list with a defensive copy of the provided slice. This is the integration point for callers (e.g. ReplModel) that own the authoritative message history.

func (*Consolidator) Stats

func (c *Consolidator) Stats() map[string]any

Stats returns a map of consolidation statistics:

  • total_messages (int)
  • total_consolidations (int)
  • paused (bool)
  • last_consolidation (string, ISO8601, empty if never)
  • estimated_tokens (int)

Jump to

Keyboard shortcuts

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