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
- Variables
- type Fact
- type MemoryStore
- func (s *MemoryStore) Delete(_ context.Context, projectName, key string) error
- func (s *MemoryStore) Get(_ context.Context, projectName, key string) (Fact, bool, error)
- func (s *MemoryStore) List(_ context.Context, projectName string) ([]Fact, error)
- func (s *MemoryStore) Upsert(_ context.Context, projectName, key, value string) error
- type PostgresStore
- func (s *PostgresStore) Close()
- func (s *PostgresStore) Delete(ctx context.Context, projectName, key string) error
- func (s *PostgresStore) Get(ctx context.Context, projectName, key string) (Fact, bool, error)
- func (s *PostgresStore) List(ctx context.Context, projectName string) ([]Fact, error)
- func (s *PostgresStore) Upsert(ctx context.Context, projectName, key, value string) error
- type Store
Constants ¶
const MaxFactValueLen = 2000
MaxFactValueLen caps a single fact's value in bytes.
const MaxFactsPerProject = 200
MaxFactsPerProject caps how many distinct keys a project's memory holds.
Variables ¶
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.
var ErrValueTooLong = errors.New("memory: value exceeds MaxFactValueLen")
ErrValueTooLong is returned by Upsert when value exceeds MaxFactValueLen.
Functions ¶
This section is empty.
Types ¶
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.
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) Delete ¶
func (s *PostgresStore) Delete(ctx context.Context, projectName, key string) error
Delete implements Store.
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.