Documentation
¶
Overview ¶
Memory: what the agent keeps between sessions. The built-in notes of each profile, MEMORY.md and USER.md, with the writes that wait for the user; the outside memory services plugins bring, one of which a profile may use beside them; and the journey of what the agent learned across its notes and its skills
Index ¶
- Constants
- Variables
- func About(target string) string
- func FirstLine(text string) string
- func HappeningTitle(kind string) string
- func Happenings() []string
- func Heading(target string) string
- func Parse(raw string) []string
- func Question(text string) string
- func Targets() []string
- func Threat(text string) string
- func Title(target string) string
- func Trivial(message string) bool
- func Words(text string) map[string]bool
- type Ask
- type Author
- type Category
- type Checkpointer
- type Delegation
- type Delegator
- type Drain
- type Event
- type Exchange
- type Handler
- type Journey
- type Kind
- type Live
- type Memory
- func (m *Memory) Approve(ctx context.Context, cfg *config.Config, id string) (Result, error)
- func (m *Memory) Begin(ctx context.Context, cfg *config.Config, session string, turn Turn)
- func (m *Memory) Checkpoints(cfg *config.Config) bool
- func (m *Memory) Close() error
- func (m *Memory) Compact(cfg *config.Config, session string, conversation []Exchange)
- func (m *Memory) Conversation(ctx context.Context, cfg *config.Config, session string, view sessions.View) ([]Exchange, error)
- func (m *Memory) Delegated(cfg *config.Config, session string, delegation Delegation)
- func (m *Memory) Delete(profile string) error
- func (m *Memory) DeleteNode(ctx context.Context, cfg *config.Config, id string) (string, Result, error)
- func (m *Memory) Drained() Drain
- func (m *Memory) EditNode(ctx context.Context, cfg *config.Config, id, text string) (Result, error)
- func (m *Memory) End(cfg *config.Config, session string, conversation []Exchange)
- func (m *Memory) Hold(ctx context.Context, cfg *config.Config, write Staged, reason string) (Staged, error)
- func (m *Memory) Journey(cfg *config.Config) Journey
- func (m *Memory) Keep(cfg *config.Config, session string, turn Exchange)
- func (m *Memory) Mirror(_ context.Context, cfg *config.Config, session, target string, ops []Op)
- func (m *Memory) Move(old, _ string) ([]string, error)
- func (m *Memory) NodeText(cfg *config.Config, id string) (string, bool, error)
- func (m *Memory) Own(cfg *config.Config) *config.Config
- func (m *Memory) PreCompress(ctx context.Context, cfg *config.Config, session string, ...) (string, error)
- func (m *Memory) Recall(ctx context.Context, cfg *config.Config, session, message string) string
- func (m *Memory) Register(registrant Registrant)
- func (m *Memory) Reject(ctx context.Context, cfg *config.Config, id string) error
- func (m *Memory) Rewrite(ctx context.Context, cfg *config.Config, message string) Ask
- func (m *Memory) Service(cfg *config.Config) (Service, bool)
- func (m *Memory) Settle(cfg *config.Config, wait time.Duration) bool
- func (m *Memory) Stop(profile string) error
- func (m *Memory) Stuck(cfg *config.Config) (stuck, skipped int)
- func (m *Memory) Telling(tell func(Told))
- func (m *Memory) Uses(cfg *config.Config) (Kind, bool)
- type Node
- type Op
- type Patched
- type Pending
- type Problem
- type Queuer
- type Registrant
- type Registry
- func (r *Registry) Host() *Memory
- func (r *Registry) Kind(name string) (Kind, bool)
- func (r *Registry) KindOf(cfg *config.Config, name string) (Kind, bool)
- func (r *Registry) Kinds() []Kind
- func (r *Registry) Live(profile string) []Kind
- func (r *Registry) Of(cfg *config.Config) []Kind
- func (r *Registry) Register(registrant Registrant)
- type Result
- type Service
- type Staged
- type Starter
- type Store
- func (s *Store) Add(ctx context.Context, target, text string) (Result, error)
- func (s *Store) Apply(ctx context.Context, target string, ops []Op) (Result, error)
- func (s *Store) Block(target string) string
- func (s *Store) Count(target string) int
- func (s *Store) Enabled(target string) bool
- func (s *Store) Entries(target string) []string
- func (s *Store) Held(target string) ([]string, int)
- func (s *Store) Limit(target string) int
- func (s *Store) On() []string
- func (s *Store) Path(target string) string
- func (s *Store) Pending() *Pending
- func (s *Store) Remove(ctx context.Context, target, entry string) (Result, error)
- func (s *Store) Resolve(ctx context.Context, target string, ops []Op) (Result, error)
- func (s *Store) Set(ctx context.Context, target, entry, text string) (Result, error)
- func (s *Store) Written() map[string]time.Time
- func (s *Store) WrittenAt(target, entry string) (time.Time, bool)
- type Told
- type Turn
- type Write
Constants ¶
const ( NodeSkill = "skill" NodeMemory = "memory" )
Kinds of node
const ( OriginAgent = pending.Foreground OriginReview = pending.Review )
Origins of a staged write, as the queue of writes held for approval names them
const ( Notes = "memory" User = "user" )
The two files of the built-in memory
const ( OpAdd = "add" OpPatch = "patch" OpRemove = "remove" )
Actions of an op
const ( // An entry of the notes written Remembered = "remembered" // A skill made, by the agent or the person Learned = "learned" // A skill changed by the agent or the person Changed = "changed" // The curator's work on a skill Curated = "curated" )
Kinds of what happened on the journey
const Delimiter = "\n§\n"
Separator of the entries of a file
const Group = "Memory"
Heading the tools of memory are listed under
const Toolset = "memory"
Toolset of the memory tool and of the tools of outside services
Variables ¶
var Calls = []string{"turn", "rewrite", "recall", "sync", "queue", "checkpoint", "compacted", "ended", "wrote", "delegated"}
Calls a service is told of, as Told names them
var ErrNoNode = errors.New("That is no longer there. Open the journey again.")
Refusal of a node that is no longer there
var ErrNoStaged = errors.New("That change is no longer waiting.")
Error of a staged write that is gone
var ErrOff = errors.New("Writes to that file are off.")
Error of a staged write whose file was turned off since
Functions ¶
func HappeningTitle ¶
What a kind of event is called on the timeline's legend
func Happenings ¶
func Happenings() []string
Kinds of what happened on the journey, in the order its timeline stacks them
func Parse ¶
Entries of the text of a file: split on the whole delimiter, so a bare section sign stays, each trimmed and none empty
func Question ¶
One clean question out of the model's answer, empty for an answer that is none: nothing, too long, no question, not about the user's memory, carrying instructions or more than one sentence. A fence, a label, quotes, control characters and runs of space are taken off
Types ¶
type Ask ¶
type Ask struct {
Message, Query string
}
What memory is searched with for a turn: the message the person sent, and the question a helper model made of it with what memory knows to look for, the message itself when none was made
type Checkpointer ¶
type Checkpointer interface {
Checkpoint(ctx context.Context, session string, conversation []Exchange, required bool) (string, error)
}
Service told before a session's context is compacted, handed what is about to be folded away, the exchanges of the person and the agent alone, so it keeps what matters of it: what it hands the summary to keep, empty for nothing; alpha's on_pre_compress. A kind that Checkpoints keeps it durably whenever it answers, which a person's Require a checkpoint counts on: required says the settings ask for one before every compaction, so its failure stops the compaction. Another is asked as best it can, its failure let be
type Delegation ¶
type Delegation struct {
Task, Result, Child string
}
The work of a subagent of a session once it ended: the task it was handed, what it answered, and its own session
type Delegator ¶
type Delegator interface {
Delegated(ctx context.Context, session string, delegation Delegation) error
}
Service told of the work of a subagent of a session once the subagent ended. A subagent runs without the memory of the session that delegated, as alpha's do: nothing is recalled for its turns and nothing of them is kept; what it did reaches memory through this alone
type Drain ¶
type Drain struct {
// drained, or timed out with work let go
Status string
// Writes and recalls that never ran, and tasks still running when the bound passed
Writes, Prefetches, Running int
}
How the last close of memory let go of the work queued for the services
type Event ¶
type Event struct {
At time.Time
Kind string
// Node it is of, empty for a skill the journey no longer holds, and the name of the skill or the first line of the entry
Node, Name string
// What happened, a sentence a person reads, such as "The curator archived it."
What string
}
One thing that happened on the journey, a mark on its timeline
type Exchange ¶
type Exchange struct {
User, Assistant string
}
One exchange of a turn: what the user sent and what the agent answered
type Journey ¶
type Journey struct {
Nodes []Node
// Ties between nodes, each counted from the node that names it
Edges int
// Categories of the skills, most first
Categories []Category
// What happened along the way, the marks of its timeline, oldest first
Events []Event
}
What the agent learned, newest first, and how it ties together
type Kind ¶
type Kind struct {
// Name of its settings, memory.<name>, and the value of memory.service that picks it
Name string
Title string
About string
// Where an account or a key is had
Site string
// Package of the program the service runs, which installs from Programs; empty for none
Program string
// Keys of its settings the Memory screen shows on its page, the secret ones asked for when it is picked
Settings []string
// What it lacks for the profile in a person's words, such as its API key, read from the settings alone; empty when it can run
Lacks func(cfg *config.Config) string
// Tools it gives the model, offered while the profile uses the kind; a call is handled by the service open for the calling session's
// profile, which then implements Handler
Tools []tools.Def
// Text of the system prompt about the service and its tools, read from the profile's own settings alone so building a prompt never opens
// the service; nil for none
Prompt func(cfg *config.Config) string
// The service of the profile of the settings, which are the profile's own and never a session's
Open func(cfg *config.Config) (Service, error)
// Its service keeps a durable checkpoint of a session before the session's context is compacted, as a Checkpointer whose answer is kept
// whenever it answers
Checkpoints bool
}
Kind of outside memory service a plugin brings, such as RetainDB. A profile uses the kind its memory.service setting names
type Live ¶
type Live interface {
Registrant
Live(profile string) []Kind
}
Registrant whose kinds come and go as it runs, such as those the extensions of a profile register: its Kinds has none, and the kinds it offers a profile are read again on every look, one of a name a fixed kind has left out. Reading them reads no setting and starts nothing
type Memory ¶
type Memory struct {
Registry
// contains filtered or unexported fields
}
Memory of every profile: the kinds of outside service the plugins registered, the service open for each profile, and the moments of a session's life they are told of: each turn as it begins, the recall it waits for, the exchange it ends with and the recall readied for the next, what a compaction is about to fold away, the work of a subagent, the messages compacted and closed
func (*Memory) Approve ¶
Applies the staged write of the id to the store, keeping it waiting when it can't be applied, such as an entry changed since; the result says what the change came to. The queue stays locked while it is applied, so the write is taken out only once it went, and no other icebath sees it gone meanwhile or applies it twice
func (*Memory) Begin ¶
Tells the service of the profile a turn of the session begins, waited for up to the bound of a recall: alpha's on_turn_start
func (*Memory) Checkpoints ¶
Whether the outside service the profile uses saves a checkpoint of a session before it is compacted, read without opening it
func (*Memory) Close ¶
Closes every outside service open once the work queued for them ran, in order, for five seconds at most, then letting go of the rest; no service opens again
func (*Memory) Compact ¶
Hands the service the messages of a session whose context was compacted, on the profile's worker
func (*Memory) Conversation ¶
func (m *Memory) Conversation(ctx context.Context, cfg *config.Config, session string, view sessions.View) ([]Exchange, error)
The messages of the session as exchanges of what the user sent and what the agent answered last, read from the store the settings of its profile name; a session of another profile is not there, so no profile's service ever hears another's messages
func (*Memory) Delegated ¶
func (m *Memory) Delegated(cfg *config.Config, session string, delegation Delegation)
Tells the service of the profile of the work of a subagent of the session once it ended, on the profile's worker: alpha's on_delegation
func (*Memory) Delete ¶
Closes the outside service of the deleted profile, whose notes and writes waiting go with its folder
func (*Memory) DeleteNode ¶
func (m *Memory) DeleteNode(ctx context.Context, cfg *config.Config, id string) (string, Result, error)
Removes the node: the entry from the notes, or the skill to the archive, a pinned skill left as it is; what became of it for a skill, what the store answered for an entry
func (*Memory) EditNode ¶
Puts the text in place of the node, as the user wrote it: the whole SKILL.md of a skill through the skill tools, so the change is logged, or the entry of the notes; what the store answered for an entry
func (*Memory) End ¶
Hands the service every message of a session that closed, on the profile's worker, and forgets the session's ask
func (*Memory) Hold ¶
func (m *Memory) Hold(ctx context.Context, cfg *config.Config, write Staged, reason string) (Staged, error)
Holds the write for the user of the profile of the settings, with why nobody could approve it where it was made, and tells them once in the sessions of the profile, where they look next
func (*Memory) Journey ¶
The journey of the profile: the skills with a sign of learning, the agent's own or used, and every entry of the notes
func (*Memory) Keep ¶
Hands the service the exchange a turn of the session ended with, and has it recall in the background for the next turn with the ask of this one, both in order on the profile's worker; a turn whose message gave nothing to search with queues no recall
func (*Memory) Mirror ¶
Tells the outside service of the profile of a change to the notes, in the background: each op with the whole entry it made, or the one it removed. The ops are pinned to the entries they picked
func (*Memory) Move ¶
Closes the service open under the old name; it opens again under the new name on its next use
func (*Memory) NodeText ¶
The whole text of a node: the entry of the notes, or the SKILL.md of the skill; whether it is a skill
func (*Memory) Own ¶
Settings of the profile the settings are of, as the profile keeps them, without the values a session sets over them
func (*Memory) PreCompress ¶
func (m *Memory) PreCompress(ctx context.Context, cfg *config.Config, session string, folded []*sessionsv1.Message, required bool) (string, error)
What the service of the profile keeps of what a compaction of the session is about to fold away, handed the exchanges of the person and the agent of those messages alone (alpha's evidence), after what was queued for it ran: what it hands the summary to keep, empty for nothing. With required, as the settings ask for a durable checkpoint before every compaction, a profile whose service keeps none, or one that failed to, is refused in words, which stops the compaction; else a service that fails is let be
func (*Memory) Recall ¶
What the service of the profile recalls for the turn's message, the one recall of a turn: none for a message that gives nothing to search with; else searched with the question a helper model makes of it, as the session's helper models on the context make it, and waited for up to the profile's bound. A long recall is saved to a file the model reads when the settings say so. The turn's ask is kept for the recall queued once the turn ends
func (*Memory) Register ¶
func (m *Memory) Register(registrant Registrant)
Adds a registrant; a registry nested in the host reaches it through Host
func (*Memory) Rewrite ¶
What memory is searched with for the message: the question the helper model of the memory_query_rewrite task makes of it, alpha's rewrite, the model being the session's helper models the context carries; the message itself when no question comes of it. It is skipped for a message that gives nothing to search with, one that already is such a question, while the task is off, and outside a session; past the task's time limit, refused, or answered with no question, the message is the query
func (*Memory) Service ¶
The outside service the profile uses, opened from the profile's own settings the first time it is asked for; false when it uses none, the one it names can't run, or memory is closed
func (*Memory) Settle ¶
Waits until the work queued for the profile's service before now ran, up to the wait; false when it did not in time
func (*Memory) Stop ¶
Closes the outside service of the profile before its folder moves, which it may hold files in
func (*Memory) Stuck ¶
Calls of the profile's service running past their bound now, and those skipped in a row as it kept being late
type Node ¶
type Node struct {
// skill:<name>, or memory: or user: and the fingerprint of the entry
ID string
Kind string
Name string
// Description of a skill, the whole entry of the notes
Detail string
// Category of a skill, the file of an entry
Category string
// State of a skill: active, stale or archived
State string
When time.Time
Uses int64
Pinned bool
// Names of the skills it is tied to: those a skill names as related, those an entry shares words with
Related []string
// File it lives in
Path string
}
One thing the agent learned: a skill it wrote or uses, or an entry of its notes
type Op ¶
type Op struct {
Action string `json:"action"`
Content string `json:"content,omitempty"`
Old string `json:"old_text,omitempty"`
// Whole entry the op edits alone, as a staged write or the screen picked it, the text of the op looked for inside it
Pinned string `json:"pinned,omitempty"`
}
One change of a batch
func (Op) Change ¶
The change the op makes to its entry as a person reads it: the entry before, empty for an add, and after, empty for a remove
func (Op) Destructive ¶
Whether the op deletes text: a patch or a remove
type Patched ¶
type Patched struct {
Before, After string
}
One entry a change patched: as it was and as it is now
type Pending ¶
type Pending struct {
// contains filtered or unexported fields
}
Writes waiting for the user of one profile: the memory writes of the profile's queue of writes held for approval, which the skills share, each a record of pending/memory in alpha's shape, those held longer than the settings keep them dropped as they are read
func (*Pending) List ¶
Writes waiting, oldest first; a record that can't be read as a memory write is left out
type Problem ¶
type Problem int
What went wrong with a change of the store, Fine when nothing did
const ( Fine Problem = iota // The file is there but could not be read or decoded, so writing it could lose what it holds Unreadable // An op the store does not take, such as one of an unknown action or one missing its text; Detail names the field Invalid // Text the strict scan flags; Detail names the pattern Flagged // The change would grow the file past its limit; Used is what it would hold Full // The text of the op is in no entry; Closest holds the entries sharing most of its words NoMatch // The text of the op is in several entries; Matches holds them Ambiguous // The span is in the entry more than once; Count says how often Repeated // The patch leaves the entry as it was Unchanged // The entry a staged write or the screen picked changed since Stale // The batch would remove every entry, which only a remove of the last one alone may Emptying )
type Queuer ¶
Service that recalls in the background after a turn for the next one, which its next Recall hands out at once
type Registrant ¶
type Registrant interface {
Kinds() []Kind
}
What a memory plugin adds: kinds of outside service
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Host ¶
Host the registry is nested in, through which plugins reach the notes of each profile, the writes waiting and the outside service each profile uses
func (*Registry) Live ¶
Kinds the live registrants offer the profile now, those of the registries nested in this one among them
func (*Registry) Of ¶
Kinds the profile of the settings may use: the fixed ones in the order plugins brought them, then those the live registrants offer it, of two of one name the first
func (*Registry) Register ¶
func (r *Registry) Register(registrant Registrant)
type Result ¶
type Result struct {
Problem Problem
// Op of a batch the problem is with, counted from 1, and its action; 0 for a problem of the whole change
At int
Action string
// Text the op named, and the field an invalid op lacks or the pattern flagged text matched
Old, Detail string
// Times a repeated span is in its entry
Count int
// Entries the change was made against, those closest to what the op named and those it matched
Entries, Closest, Matches []string
// Characters the file holds after the change, or would hold, and its limit
Used, Limit int
// Entry each destructive op of the batch picked, empty for an add
Picked []string
// What the change did
Added []string
Patches []Patched
Removed []string
// An add of an entry already there, which changed nothing
Duplicate bool
}
What a change of the store came to
func (Result) Consolidating ¶
Whether the problem is one of making room or of picking an entry, which a turn retrying the memory tool counts
type Service ¶
type Service interface {
// What the service recalls for the turn's message, which the turn's message carries; empty for nothing. The ask holds the message and
// the query memory is searched with, a question a helper model made of the message, the message itself when none was made
Recall(ctx context.Context, session string, ask Ask) (string, error)
// Keeps one finished exchange
Sync(ctx context.Context, session string, turn Exchange) error
// The session closed: what it wants to keep of the whole session
Ended(ctx context.Context, session string, conversation []Exchange) error
// The session's context was compacted, the messages before it given, so what it holds is kept before it is folded away
Compacted(ctx context.Context, session string, conversation []Exchange) error
// The memory tool changed the built-in notes, which a service may mirror
Wrote(ctx context.Context, session string, write Write) error
// Lets go of what it holds, such as a queue of writes, waiting for them
Close() error
}
Outside service open for one profile, which every session of the profile uses. What it may do besides is an ability of its own: Handler, Checkpointer, Starter, Queuer, Delegator
type Staged ¶
type Staged struct {
ID string
Target string
Ops []Op
// Who asked for it: the agent, or a review the user did not ask for
Origin string
// Session it was asked in, whose outside service hears of it once approved
Session string
Created time.Time
}
A write of the memory tool held for the user: one target and its operations, each destructive one pinned to the entry it was picked against
type Store ¶
type Store struct {
Dir string
MemoryLimit, UserLimit int
MemoryOn, UserOn bool
// How long a write held for the user waits before it is dropped, none for until it is answered
PendingExpiry time.Duration
}
The built-in memory of one profile: MEMORY.md and USER.md in its memories folder, each a list of entries within a character limit. Every change holds the file's lock, which other processes and every other change of this one wait for
func (*Store) Apply ¶
Applies add, patch and remove ops at once, all or none, the limit checked on what they make together
func (*Store) Block ¶
Block of the system prompt for the target: its heading, how full it is and its entries, any entry the strict scan flags left out; empty for no entries
func (*Store) Held ¶
Entries of the target on disk and the characters they hold, none when it can't be read
func (*Store) Resolve ¶
Entry each destructive op of the batch picks now, read under the lock, or the problem applying it would meet; nothing is written
func (*Store) Set ¶
Puts the text in place of the whole entry, as the Memory screen edits one; an emptied entry is removed
type Told ¶
type Told struct {
// turn, rewrite, recall, sync, queue, checkpoint, compacted, ended, wrote, delegated
Call string
// ok, failed, late (past its bound, left running) or skipped (the service kept being late, so it was not asked)
Outcome string
Took time.Duration
}
One call of a service as memory tells of it: the moment, how it went and how long it took
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Screens of memory: the notes of the agent and the writes waiting on them, the outside memory services, and the journey of what the agent learned
|
Screens of memory: the notes of the agent and the writes waiting on them, the outside memory services, and the journey of what the agent learned |