Documentation
¶
Overview ¶
Package memdistill reads the agents' finished conversations and asks a model what in them is worth remembering: a preference the user stated, a rule learned from a correction, a fact of the project the code doesn't say. What it finds waits in memory as a candidate (To review) until the user keeps it; nothing it proposes reaches an agent before.
It runs when switched on (State.On), on sessions quiet for Quiet, each once for what it held when read: a session that goes on is read again later, whole. The hourly run reads at most PerRun; one the user asked for (ReadAll) reads every one due, and Stop ends it. The model is the one picked, else the caller's automatic choice. The request goes through magpie's own gateway (Complete), so masking and routing apply as to any agent's request.
Index ¶
- Constants
- Variables
- func Dream(ctx context.Context, auto string, complete Complete) ([]memory.Change, error)
- func Dreaming() bool
- func Dreams(s State, t time.Time) bool
- func Keep(ctx context.Context, first, interval time.Duration, auto func() string, ...)
- func Progress() (int, int)
- func Running() bool
- func Stop()
- func Undo() (int, error)
- type Complete
- type Result
- type State
Constants ¶
const ( // DreamHour is the local hour a tidy is due from each day DreamHour = 3 // Unreviewed is how long a distilled candidate waits for review before // a tidy sets it aside Unreviewed = 30 * 24 * time.Hour )
const ( // Quiet is how long a session has had no turn before it is read: one // still going is read when it stops Quiet = 30 * time.Minute // PerRun caps the sessions an hourly run sends to the model: more // than a busy hour brings, so only a backlog waits for the next run. // A run the user asked for (ReadAll) reads every one due // (RealZeroP27 on X: at 10 an hour, 400 took 40 hours) PerRun = 30 // Back is how far back a run looks the first time it is switched on, // when no range is picked (State.Days 0) Back = 7 * 24 * time.Hour // All is State.Days for every conversation listed: the latest // Listed, read at once when picked (ReadAll), else PerRun an hour All = -1 // Listed is how many of the latest sessions a run looks through Listed = 400 // MinTurns is the fewest things the user said for a session to be read MinTurns = 2 // MaxPerSession caps what one session may propose MaxPerSession = 5 )
const Agent = "memory"
Agent is the agent id the model requests are made as (gateway.TokenFor), so Usage counts them apart, and whose sessions are never read.
Variables ¶
var ErrRunning = errors.New("already reading conversations")
ErrRunning is a run asked for while one is going.
Path is distill.json; a variable for tests.
var Ranges = []int{7, 30, 90, 365, All}
Ranges are the ranges, in days, reading can be set to look back: Back's seven first, All last.
Functions ¶
func Dream ¶
Dream tidies memory now, switched on or not, with the model picked or auto. A request that fails changes nothing; the error is kept and the tidy is tried again on the next tick.
func Dreaming ¶
func Dreaming() bool
Dreaming says a tidy is going in this process (Running says so too).
func Dreams ¶
Dreams says a tidy is due at t: switched on, and none done since the last DreamHour passed (local time), nor since it was switched on.
func Keep ¶
func Keep(ctx context.Context, first, interval time.Duration, auto func() string, complete Complete)
Keep runs Run first after first, then every interval, until ctx ends, and Dream after it when one is due (Dreams); auto gives the automatic model at each run. Each tick applies memory's retention first (memory.Prune), distilling on or off.
func Progress ¶
Progress is how many sessions the run going has gone through, of how many it will, read or passed over; 0, 0 when none is going or it is still listing them.
Types ¶
type Complete ¶
Complete sends one request to model, asked to reason at effort ("" the model's own default): a system text and one user message, and returns the reply's text.
type Result ¶
Result is what one run did.
type State ¶
type State struct {
On bool `json:"on,omitempty"`
// Model is the model picked; "" is the automatic choice
Model string `json:"model,omitempty"`
// Days is how far back reading looks, in days, from when it was
// switched on or the range was picked: 0 is Back, All every
// conversation listed (Ranges)
Days int `json:"days,omitempty"`
// Effort is the reasoning level the model is asked at, reading and
// tidying, fitted to its own levels as it is sent; "" its default
Effort string `json:"effort,omitempty"`
// Since is when it was switched on or the range picked, less the
// range: older sessions aren't read. Zero with All
Since time.Time `json:"since,omitzero"`
// Done is each read session's last turn when it was read, by
// agent/id
Done map[string]time.Time `json:"done,omitempty"`
// the last run: when, with which model, how many sessions read, how
// many memories proposed, and what stopped it
Last time.Time `json:"last,omitzero"`
LastModel string `json:"lastModel,omitempty"`
Read int `json:"read,omitempty"`
Added int `json:"added,omitempty"`
Error string `json:"error,omitempty"`
// Left is how many were due and not read when the last run ended:
// stopped, failed or past PerRun
Left int `json:"left,omitempty"`
// Reads is the reading the Done marks were made by (reads): marks
// an older one made of an agent it read wrong are dropped
Reads int `json:"reads,omitempty"`
// Dream is the nightly tidy switched on (dream.go), DreamSince when
Dream bool `json:"dream,omitempty"`
DreamSince time.Time `json:"dreamSince,omitzero"`
// the last tidy that went through: when, with which model, and what it
// changed, undone or not; DreamError is what stopped the last one tried
Dreamt time.Time `json:"dreamt,omitzero"`
DreamModel string `json:"dreamModel,omitempty"`
DreamError string `json:"dreamError,omitempty"`
Changes []memory.Change `json:"changes,omitempty"`
Undone bool `json:"undone,omitempty"`
}
State is distill.json.
func Load ¶
Load reads distill.json; a missing file is the default (off). One that can't be read is an error, never the default: a run doesn't start, and a change isn't written over it.
func Set ¶
Set switches distilling on or off and picks its model ("" automatic). Switched on from off, it looks back the range picked (Back by default) from now; switched off, the run going stops.
func SetDream ¶
SetDream switches the nightly tidy on or off. Switched on, the first is due at the next DreamHour; Tidy now does one at once.