memory

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 19 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package memory is what the assistant remembers, which is shared by every session and agent: the details of the person it's talking to, and of itself, such as their names, where the person is, and their time zone and language, which are in the system prompt, each of which is known, not known, or declined, so it isn't. The memory is a namespace of a toolkit, whose tools set them, and whose system prompt has them, with the time.

Index

Constants

View Source
const (
	DetailTable = "detail"

	// MemoryTable is the table of the events of the memories, whose schema
	// is Name, and whose rows are their keys
	MemoryTable = "memory"
)

DetailTable is the table of the events of the details, whose schema is Name, and whose rows are their fields, such as location

View Source
const Name = "memory"

Name is the name of the namespace of the memory's tools

Variables

This section is empty.

Functions

func SortMemories

func SortMemories(memories []schema.Memory)

SortMemories sorts the memories, the most recently changed first, and then by their keys, as a store lists them

Types

type Memory

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

Memory is what the assistant remembers, which is kept in a store. It's a namespace of a toolkit, whose system prompt has the details, and the time, and whose tools change them. It's safe to use concurrently.

func New

func New(ctx context.Context, store Store, opts ...Opt) (_ *Memory, err error)

New returns the memory, with the details in the store, and the options, such as the broadcaster it publishes its changes to, and the tracer. Returns ErrBadParameter when there's no store, or an option isn't valid, and the store's errors.

func (*Memory) Description

func (*Memory) Description() string

Description returns what the memory is

func (*Memory) Details

func (m *Memory) Details() schema.Details

Details returns the details

func (*Memory) Forget

func (m *Memory) Forget(ctx context.Context, key string) (_ schema.Memory, err error)

Forget deletes the memory with the key, publishes that it was, and returns it, as it was. Returns ErrNotFound when there's none.

func (*Memory) ForgetLine

func (m *Memory) ForgetLine(ctx context.Context, key, line string) (_ schema.Memory, err error)

ForgetLine takes the line out of the body of the memory with the key, apart from the space around it, and a bullet, such as "- ", or forgets the memory, when there's nothing left of it, publishes the change, and returns the memory, as it is, or was, when it's forgotten. Returns ErrNotFound when there's no memory with the key, or it hasn't the line.

func (*Memory) GetMemory

func (m *Memory) GetMemory(ctx context.Context, key string) (_ schema.Memory, err error)

GetMemory returns the memory with the key, or ErrNotFound when there's none

func (*Memory) ListMemories

func (m *Memory) ListMemories(ctx context.Context, req schema.MemoryListRequest) (_ schema.MemoryList, err error)

ListMemories returns the memories which match the request's query, the most recently changed first, of its page, and how many there are

func (*Memory) Name

func (*Memory) Name() string

func (*Memory) Notify

func (*Memory) Notify(func(eventschema.EventAction, string))

Notify does nothing, as the memory's tools don't change

func (*Memory) Remember

func (m *Memory) Remember(ctx context.Context, meta schema.MemoryMeta, version string) (_ schema.Memory, created bool, err error)

Remember creates the memory, when the version is empty, or replaces the memory with its key, when the version is its version, and it's changed, publishes the change, and returns the memory, and whether it was created. Returns ErrBadParameter when it isn't valid, ErrConflict when there's a memory with its key, and the version isn't its version, as it was changed since it was seen, or there's none, and the version isn't empty, and the store's errors.

func (*Memory) SetDetail

func (m *Memory) SetDetail(ctx context.Context, field schema.Field, detail *schema.Detail) (_ schema.Details, err error)

SetDetail sets the detail of the field, which is its value, or that it's declined, or forgets it, when it's nil, so it isn't known, in the store, publishes the change, when it changed, and returns the details. Returns ErrBadParameter when the field, or the detail, isn't valid, and the store's errors, when the details aren't changed.

func (*Memory) SystemPrompt

func (m *Memory) SystemPrompt() string

SystemPrompt returns the time, in the person's time zone, when it's known, or the system's, and the details which are known, and which aren't, so the model asks for them, and remembers them. The details which are declined aren't in it, so they aren't asked for.

func (*Memory) SystemPromptFor

func (m *Memory) SystemPromptFor(tools []string) string

SystemPromptFor returns the system prompt, when the model can call the tools, or all of them, when they're nil: when the person's messages were sent, the details, and, with the set_detail tool, those which aren't known, and how to remember them, and, with the memories tool, how to search, keep and use memories

func (*Memory) Tools

func (m *Memory) Tools() []llm.Tool

Tools returns the memory's tools

type Opt

type Opt func(*opt) error

Opt is an option of the memory

func WithBroadcaster

func WithBroadcaster(b *broadcaster.Broadcaster) Opt

WithBroadcaster sets the broadcaster which the memory publishes its changes to: when a detail becomes known, or declined, which is created, changes, which is updated, or is forgotten, which is deleted. Their schema is Name, which is memory, their table is DetailTable, their rows are the details' fields, such as location, and their data is the detail, when there is one.

func WithTracer

func WithTracer(tracer trace.Tracer) Opt

WithTracer sets the tracer which traces the memory's changes, and loading its details, or none, when it's nil

type Store

type Store interface {
	// Details returns the details, which are all not known, when none are
	// stored
	Details(context.Context) (schema.Details, error)

	// PutDetails replaces the details
	PutDetails(context.Context, schema.Details) error

	// ListMemories returns the memories which match the query, as Matches
	// says, the most recently changed first
	ListMemories(ctx context.Context, q string) ([]schema.Memory, error)

	// GetMemory returns the memory with the key, or ErrNotFound when there's
	// none
	GetMemory(ctx context.Context, key string) (schema.Memory, error)

	// PutMemory creates the memory, or replaces the memory with its key
	PutMemory(context.Context, schema.Memory) error

	// DeleteMemory deletes the memory with the key, or returns ErrNotFound
	// when there's none
	DeleteMemory(ctx context.Context, key string) error
}

Store keeps the details, and the memories, such as in files, or a database, so they're kept when the server restarts

func NewStore

func NewStore() Store

NewStore returns a store which keeps the details, and the memories, in memory, so they aren't kept when the process ends, such as for tests, and examples

Directories

Path Synopsis
Package cmd has the memory's commands and flags
Package cmd has the memory's commands and flags
Package httpclient is a client of the memory's HTTP API
Package httpclient is a client of the memory's HTTP API
Package httphandler has the memory's HTTP API, which gets, sets and forgets the details it keeps, and lists, gets, remembers and forgets its memories
Package httphandler has the memory's HTTP API, which gets, sets and forgets the details it keeps, and lists, gets, remembers and forgets its memories

Jump to

Keyboard shortcuts

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