memory

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

Documentation

Overview

Package memory stores durable project-scoped facts the assistant learns while working with a project — goals, conventions, decisions, standing constraints — so they persist across conversations and are visible to every user working on the same project. This is distinct from internal/history, which replays recent turns within one conversation: memory here is small, explicit (written only via the memory_remember / memory_forget capability tools), and keyed by projectName alone.

Index

Constants

View Source
const MaxFactValueLen = 2000

MaxFactValueLen caps a single fact's value in bytes.

View Source
const MaxFactsPerProject = 200

MaxFactsPerProject caps how many distinct keys a project's memory holds.

Variables

View Source
var ErrProjectFull = errors.New("memory: project fact count exceeds MaxFactsPerProject")

ErrProjectFull is returned by Upsert when writing a brand-new key would exceed MaxFactsPerProject for that project. Losing a remembered fact silently is higher-stakes than losing an old chat turn, so unlike history's turn-count pruning this rejects instead of evicting — the calling tool surfaces the error to the model, which can ask the user to forget something first.

View Source
var ErrValueTooLong = errors.New("memory: value exceeds MaxFactValueLen")

ErrValueTooLong is returned by Upsert when value exceeds MaxFactValueLen.

Functions

This section is empty.

Types

type Fact

type Fact struct {
	Key       string
	Value     string
	UpdatedAt time.Time
}

Fact is one remembered project-scoped key/value pair.

type MemoryStore

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

MemoryStore is an in-process Store. Facts live for the lifetime of the service process; PostgresStore is the durable equivalent behind the same interface.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore returns an empty in-memory store.

func (*MemoryStore) Delete

func (s *MemoryStore) Delete(_ context.Context, projectName, key string) error

Delete implements Store.

func (*MemoryStore) Get

func (s *MemoryStore) Get(_ context.Context, projectName, key string) (Fact, bool, error)

Get implements Store.

func (*MemoryStore) List

func (s *MemoryStore) List(_ context.Context, projectName string) ([]Fact, error)

List implements Store.

func (*MemoryStore) Upsert

func (s *MemoryStore) Upsert(_ context.Context, projectName, key, value string) error

Upsert implements Store.

type PostgresStore

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

PostgresStore is a durable Store on PostgreSQL. Safe for concurrent use. Construct with NewPostgresStore, release with Close.

func NewPostgresStore

func NewPostgresStore(ctx context.Context, databaseURL string, logger *slog.Logger) (*PostgresStore, error)

NewPostgresStore connects to databaseURL (a postgres:// URL), verifies the connection, and applies the schema. It fails fast on an unreachable or unwilling database.

func (*PostgresStore) Close

func (s *PostgresStore) Close()

Close releases the connection pool.

func (*PostgresStore) Delete

func (s *PostgresStore) Delete(ctx context.Context, projectName, key string) error

Delete implements Store.

func (*PostgresStore) Get

func (s *PostgresStore) Get(ctx context.Context, projectName, key string) (Fact, bool, error)

Get implements Store.

func (*PostgresStore) List

func (s *PostgresStore) List(ctx context.Context, projectName string) ([]Fact, error)

List implements Store.

func (*PostgresStore) Upsert

func (s *PostgresStore) Upsert(ctx context.Context, projectName, key, value string) error

Upsert implements Store. The project fact-count bound is enforced inside the same transaction as the write, so concurrent inserts cannot race past MaxFactsPerProject.

type Store

type Store interface {
	// List returns a project's facts, unordered. An unknown project yields
	// nil, nil.
	List(ctx context.Context, projectName string) ([]Fact, error)
	// Get returns one fact by key, or ok=false if it is not set.
	Get(ctx context.Context, projectName, key string) (fact Fact, ok bool, err error)
	// Upsert writes or replaces a fact. It returns ErrValueTooLong or
	// ErrProjectFull if a bound is violated; the store is left unchanged.
	Upsert(ctx context.Context, projectName, key, value string) error
	// Delete removes a fact. Deleting an unset key is a no-op, not an error.
	Delete(ctx context.Context, projectName, key string) error
}

Store persists and recalls a project's facts. Implementations must be safe for concurrent use.

Jump to

Keyboard shortcuts

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