memdistill

package
v0.1.4792 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 20 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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
)
View Source
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
)
View Source
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

View Source
var ErrRunning = errors.New("already reading conversations")

ErrRunning is a run asked for while one is going.

View Source
var Path = func() string { return appdir.Join(appdir.Config(), "distill.json") }

Path is distill.json; a variable for tests.

View Source
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

func Dream(ctx context.Context, auto string, complete Complete) ([]memory.Change, error)

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

func Dreams(s State, t time.Time) bool

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

func Progress() (int, int)

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.

func Running

func Running() bool

Running says a run is going in this process.

func Stop

func Stop()

Stop ends the run going in this process, if any: the request in flight is dropped and its session read next time. It isn't an error.

func Undo

func Undo() (int, error)

Undo puts back what the last tidy changed, as far as the user hasn't changed it since, once.

Types

type Complete

type Complete func(ctx context.Context, model, effort, system, user string) (string, error)

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

type Result struct {
	Read  int
	Added int
}

Result is what one run did.

func ReadAll

func ReadAll(ctx context.Context, auto string, complete Complete) (Result, error)

ReadAll is Run over every session due, for a run the user asked for: switched on, a model or a longer range picked, Read now. Stop ends it.

func Run

func Run(ctx context.Context, auto string, complete Complete) (Result, error)

Run reads up to PerRun of the sessions due, if switched on, with auto when the state names no model. A model that fails stops the run: the sessions not read yet are read next time.

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

func Load() (State, error)

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

func Set(on bool, model string) (State, error)

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

func SetDream(on bool) (State, error)

SetDream switches the nightly tidy on or off. Switched on, the first is due at the next DreamHour; Tidy now does one at once.

func SetEffort

func SetEffort(effort string) (State, error)

SetEffort picks the reasoning level the model is asked at, "" for its own default. A level the model doesn't have is fitted to the nearest it has when sent.

func SetRange

func SetRange(days int) (State, error)

SetRange picks how far back reading looks: one of Ranges, from now. A conversation read already isn't read again for a longer range; one older than a shorter range isn't read.

Jump to

Keyboard shortcuts

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