memory

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Overview

Package memory manages the engine's local working copy of an agent's declared memory files. A configured store holds the durable copy; this manager pulls a snapshot at boot, exposes read/append/edit operations to LLM agent nodes, and pushes every successful write back through the store synchronously. Sync-on-write keeps the durable copy ahead of in-memory state in case the engine process is killed without graceful shutdown.

Index

Constants

This section is empty.

Variables

View Source
var ErrEditNoMatch = errors.New("memory edit: old_string not found in file")

ErrEditNoMatch is returned by Edit when the supplied old_string isn't present in the file. The LLM is expected to recover by re-reading.

View Source
var ErrFileNotFound = errors.New("memory file not found")

ErrFileNotFound is returned when the LLM references a memory file that isn't declared for this agent.

View Source
var ErrSizeExceeded = errors.New("memory write would exceed max size")

ErrSizeExceeded is returned when an append/edit would push the file past its declared maxSizeBytes cap.

Functions

func IndexCard

func IndexCard(refs []workflow.MemoryRef, mgr *Manager) (string, error)

IndexCard renders the auto-injected memory index block prepended to the LLM agent's system prompt. One line per file with name, mode, size, and description so the LLM can decide what to fetch.

func Tools

func Tools(refs []workflow.MemoryRef, mgr *Manager) ([]llmproxy.Tool, error)

Tools synthesizes the LLM-callable tools (read_memory, append_memory, edit_memory) for the given memory refs. Each tool's `file` parameter is constrained by enum to the human names of files this agent is allowed to touch (read-only refs excluded from write enums). Internally, each tool resolves the chosen name to its uid before calling the manager.

Returns nil when refs is empty.

func ValidateRefs

func ValidateRefs(refs []workflow.MemoryRef, mgr *Manager) error

ValidateRefs checks that every ref's uid is present in the manager. Run at Setup() time so a misconfigured workflow fails the build instead of failing at the first LLM tool call.

Types

type Card

type Card struct {
	UID         string
	Name        string
	Description string
	SizeBytes   int
}

Card is the metadata used to render an entry in the auto-injected memory index in the LLM agent's system prompt. Size is in bytes; the LLM treats it as a hint, not a hard contract.

type Manager

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

Manager is the engine-side memory subsystem. One instance per engine process. Files are keyed internally by uid (stable across renames); the LLM-facing tool layer resolves human names to uids via Card.

func NewManager

func NewManager(dir string, store engine.MemoryStore) *Manager

NewManager constructs a manager that writes its working copy into dir and syncs through the given store. The directory is created lazily on Restore.

func (*Manager) Append

func (m *Manager) Append(ctx context.Context, uid, content string) error

Append concatenates content to the file identified by uid, persists locally, and pushes the new full content through the store. Returns ErrSizeExceeded if the result would exceed the declared cap.

func (*Manager) Card

func (m *Manager) Card(uid string) (Card, error)

Card returns the metadata for the file identified by uid. Tool builders use this to translate refs into LLM-facing enums and index cards.

func (*Manager) Edit

func (m *Manager) Edit(ctx context.Context, uid, oldStr, newStr string) error

Edit performs a single find/replace against the file identified by uid. Returns ErrEditNoMatch if oldStr isn't present. First match only, matching Claude Code's Edit semantics.

func (*Manager) Read

func (m *Manager) Read(uid string) (string, error)

Read returns the current content of the file identified by uid.

func (*Manager) Restore

func (m *Manager) Restore(ctx context.Context) error

Restore pulls the full memory snapshot from the store and overwrites the local working copy. Called from Builder.Build, so each deploy refreshes state (covers boot AND post-rename redeploy).

func (*Manager) UIDs

func (m *Manager) UIDs() []string

UIDs returns every declared memory file's uid. Used by ValidateRefs to detect refs that don't match any current declaration.

Jump to

Keyboard shortcuts

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