Dreamer
Go · package github.com/muthuishere/toolnexus/golang/agents · SPEC §7E · golang/agents/home.go
func Dreamer(dir string, opts DreamerOptions) (*Agent, error) // package agents
type DreamerOptions struct { Store tn.ConversationStore; Instructions, Name, Model string }
// the one-line form, on FromDir:type DreamOptions struct { EveryMs int64; Store tn.ConversationStore; Instructions string }FromDir(dir, FromDirOptions{Dream: &DreamOptions{...}})Dreamer builds the dreamer: a plain agent whose job is to keep a persona’s memory true. Its
tools are exactly two — memory (with the notes tier on, over dir) and
transcript_search (over your conversation
store) — never the persona’s shell or file tools. Its soul is one ## HEARTBEAT.md section:
the SPEC constant DREAM_PROMPT, then DREAM.md from the home dir (if present), then
instructions (if given). Construction fails without a store, or with a store that cannot
list().
Each pass works in order: verify every index line and note against the transcripts (fix
what they contradict, drop only what they contradict — a claim they do not mention stays) → demote detail out of MEMORY.md
into a note behind a [[slug]] pointer → merge duplicate notes → repair links → log
one dream: … entry to memory/log.md. A pass with nothing to change writes nothing and replies
HEARTBEAT_OK, which the heartbeat keeps silent.
When to use it
Section titled “When to use it”Use it for a long-lived persona whose memory is written by the model across many sessions: a personal assistant, a support agent, an on-call operator. Those memories drift — a wrong fact gets recorded once and then re-read every session. The dreamer fixes that offline, against the transcripts, so the agent’s memory gets better while it sleeps, not worse.
Skip it for one-shot workers, for memory a human curates by hand, or when you keep no transcripts (there is nothing to verify against). See the Dreaming guide for the full when-to-use table and cadence advice.
Why this and not the alternative
Section titled “Why this and not the alternative”A hand-written HEARTBEAT.md consolidator (the earlier recipe) can only tidy what memory
already says. It cannot tell a true note from a wrong one. The dreamer checks claims against the
transcripts, which are the ground truth, and records every change in memory/log.md, so a bad
“tidy” can be seen and reverted.
Examples
Section titled “Examples”1. The smallest useful call — dream nightly, one line
Section titled “1. The smallest useful call — dream nightly, one line”import ( toolnexus "github.com/muthuishere/toolnexus/golang" "github.com/muthuishere/toolnexus/golang/agents")
store, _ := toolnexus.NewFileConversationStore("./data/conversations") // the transcripts your client saves
ava := agents.FromDir("./personas/ava", agents.FromDirOptions{ Notes: true, MemoryIndexCap: &agents.IndexCap{}, // zero fields ⇒ the 200-line / 25600-byte preset Dream: &agents.DreamOptions{EveryMs: 24 * 60 * 60 * 1000, Store: store}, // dream nightly})started, _ := agents.StartAgent(ava, agents.StartOptions{Options: agents.Options{LLM: llm}, EveryMs: 30 * 60 * 1000})defer started.Stop() // stops the persona and its dreamer2. The realistic case — your own schedule
Section titled “2. The realistic case — your own schedule”store, _ := toolnexus.NewFileConversationStore("./data/conversations")d, err := agents.Dreamer("./personas/ava", agents.DreamerOptions{Store: store}) // a plain *Agentif err != nil { log.Fatal(err) // "dreamer: store is required"}
// Your schedule: a 6-hourly heartbeat with its own OnBeat.started, _ := agents.StartAgent(d, agents.StartOptions{ Options: agents.Options{LLM: llm}, EveryMs: 6 * 60 * 60 * 1000, OnBeat: func(summary string) { log.Println("dreamt:", summary) },})3. The full surface — goal-focused prose and a single pass on demand
Section titled “3. The full surface — goal-focused prose and a single pass on demand”store, _ := toolnexus.NewFileConversationStore("./data/conversations")d, _ := agents.Dreamer("./personas/ava", agents.DreamerOptions{ Store: store, Instructions: "Pay special attention to the user's travel preferences.", // after DREAM.md Model: "openai/gpt-4o-mini",})
// One pass, now — from a CI job, a button, or a test.r, _ := d.Run(agents.Options{LLM: llm}, agents.HeartbeatPrompt)fmt.Println(r.Text) // "HEARTBEAT_OK" when memory already matched the transcriptsPut standing guidance in DREAM.md in the home dir (it is read when the dreamer is built);
use instructions for guidance that depends on the host.
Options
Section titled “Options”| Option | Default | What it does |
|---|---|---|
| store | — (required) | The conversation store to verify against. It must support list(). |
| instructions | none | Host prose appended after DREAM_PROMPT and DREAM.md. |
| name | <basename(dir)>-dreamer |
The agent’s name. |
| model | inherit |
Model id. inherit uses the runtime’s model; a cheaper model is usually enough. |
On FromDir, the dream option takes everyMs (must be > 0), store, and optional
instructions. Leaving it out changes nothing.
See also
Section titled “See also”- Dreaming guide — the memory layout, what a pass does, safety and cadence.
transcriptSearchTool— the read-only search the dreamer verifies with.memoryTool— the notes tier (note:<slug>,read,list) the dreamer writes with.fromDir— where the one-linedreamoption lives.