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 ¶
- Variables
- type ConsolidationResult
- type Consolidator
- func (c *Consolidator) CanConsolidate() bool
- func (c *Consolidator) Consolidate() *ConsolidationResult
- func (c *Consolidator) IsPaused() bool
- func (c *Consolidator) Messages() []types.Message
- func (c *Consolidator) Pause()
- func (c *Consolidator) Resume()
- func (c *Consolidator) SetMessages(messages []types.Message)
- func (c *Consolidator) Stats() map[string]any
Constants ¶
This section is empty.
Variables ¶
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 (*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) 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)