memory

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithCompactThreshold

func WithCompactThreshold(n int) memoryConfigFunc

WithCompactThreshold triggers memory compaction when the number of conversations is greater than or equal to n. On compaction all but the two most recent conversations are summarised and merged into long-term memory.

func WithCompactTokenThreshold added in v0.0.24

func WithCompactTokenThreshold(n int) memoryConfigFunc

WithCompactTokenThreshold triggers memory compaction when the total approximate token count of short-term memory reaches or exceeds n tokens. When triggered, the oldest conversations totaling approximately n/2 tokens are summarized and merged into long-term memory.

This option takes precedence over WithCompactThreshold when both are set.

func WithLongTermMemoryTTL

func WithLongTermMemoryTTL(v time.Duration) memoryConfigFunc

Set long term memory TTL to v.

func WithShortTermMemoryTTL

func WithShortTermMemoryTTL(v time.Duration) memoryConfigFunc

Set short term memory TTL to v.

Types

type Conversation

type Conversation struct {
	Time      atom.Time `json:"time"`
	User      string    `json:"user"`
	Assistant string    `json:"assistant"`
}

type TempMemory

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

func NewTempMemory

func NewTempMemory(key string, agent *agents.MemorySummarizer, ops ...memoryConfigFunc) *TempMemory

NewTempMemory creates a TempMemory backed by Redis.

Default compaction policy: token-based at 4000 tokens (~4–6 typical customer-support exchanges). This threshold keeps recent detail without bloating the model's context window. On compaction the oldest conversations totalling ~2000 tokens are summarised and merged into long-term memory, leaving ~2000 tokens of recent context intact.

Override with WithCompactTokenThreshold (recommended) or WithCompactThreshold (round-based, legacy). Both the short-term and long-term stores default to a 30-day TTL.

func (*TempMemory) Append

func (m *TempMemory) Append(rail miso.Rail, c Conversation) error

func (*TempMemory) Load

func (m *TempMemory) Load(rail miso.Rail) (_longTerm string, shortTerm []Conversation, _err error)

func (*TempMemory) LoadFormatted

func (m *TempMemory) LoadFormatted(rail miso.Rail, lock bool) (_longTerm string, _shortTerm string, _err error)

func (*TempMemory) LoadLocked

func (m *TempMemory) LoadLocked(rail miso.Rail) (_longTerm string, shortTerm []Conversation, _err error)

Jump to

Keyboard shortcuts

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