Memory & Knowledge
Task state, user preferences, and external source material can all influence an answer, but they should not share one storage and loading policy. aibuddy keeps them in task, user, and document scopes and applies a different selection path before each enters the model working set.
Three information classes use different scopes
| Information system | Appropriate content | Lifecycle | Path into active work |
|---|---|---|---|
| Task context | Current goal, plan, tool results, and execution state | One task | Assembled by the runtime and compacted at thresholds |
| User memory | Stable preferences, behavioral feedback, and non-recoverable project background | One user across tasks | Select from a lightweight index, then read matched bodies |
| Knowledge base | Source material whose provenance and section structure must remain intact | Personal or system scope | Publish, attach to a task, then read through a knowledge subagent |
For example, “use a concise format for this report” belongs to the current task; “use a concise format for every weekly report” can become user memory; and a company policy remains a reviewable, citable knowledge document. Scope separation prevents transient state from becoming a lasting preference and avoids replacing formal sources with uncited memory.
Memory is a maintainable user record
Each memory is an independent Markdown record. Frontmatter stores its name, description, type, provenance, and recall telemetry; the body stores the complete content. Types express intended use rather than merely copying the conversation topic:
| Type | Stored content |
|---|---|
user | Role, expertise, background, and stable preferences |
feedback | Corrections or confirmations about agent behavior |
project | Durable project context that cannot be recovered from project files or connected systems |
reference | Pointers to external systems, pages, or source material |
Explicit memory-tool writes receive manual provenance, while background extraction receives auto; the system sets provenance and the model cannot declare it. Create and update are distinct operations. An update preserves the original provenance, recallCount, and lastRecalledAt, preventing an accidental same-name write from breaking record continuity.
The agent can save, recall, update, or delete an individual memory. Clearing the complete memory set remains a user-side management capability and is not exposed as an agent memory tool, preventing one model call from removing the user’s entire collection.
Memory is isolated per user and persists outside task sandboxes. The storage layer needs only narrow list, read, write, and delete operations, allowing a filesystem, object store, or database to retain the same maintenance and recall semantics.
Recall selects an index before reading bodies
The runtime does not add every memory to every model request. Recall currently has three stages:
- Scan memory frontmatter into a manifest containing only type, filename, modification date, and a short description.
- Ask a separate lightweight model to select records clearly relevant to the current request.
- Validate the filenames and load only the selected bodies, currently up to 5 per recall.
This path separates relevance judgment from full-content loading. The selector can reason semantically, while long-lived records consume main-task context only after a match. If model selection is unavailable, the memory tool can fall back to lexical matching across descriptions and bodies. Selection or read failure yields an empty result instead of stopping the main task.
The current index window scans at most 200 memories and orders them by modification time. Successful recall updates recallCount, lastRecalledAt, and file activity, helping records still in use remain in the active window. When a memory result participates in later reasoning, it is compacted to count and status; the client can still display the surfaced content without making later steps repeatedly carry every body.
Automatic extraction is a constrained write path
Background extraction does not turn every conversation into memory. At task completion, the system inspects only the latest 3 user-assistant pairs and first applies deterministic cues for potentially durable information. Without a preference, identity, feedback, or persistent-project signal, no model extraction starts. The process also skips a window whose latest assistant turn already invoked explicit save, update, or delete memory operations.
A candidate must be user- or durable-project-specific, likely to remain valid, and unavailable from files or connected systems. The write path then reconciles it against existing records:
- Discard low-salience candidates.
- Treat equivalent content as a no-op.
- Reuse an existing record when same-type description similarity reaches the current
0.6threshold. - Prevent automatic extraction from overwriting a
manualmemory. - Preserve filename, provenance, and recall telemetry on updates.
Automatic extraction is therefore a “cue gate—model judgment—similarity merge—provenance protection” process, not a transcript archive. Failure at any stage is logged and skipped without affecting task completion.
Knowledge must be published before entering a task
Knowledge import preserves Markdown structure and derives heading levels, stable section anchors, line ranges, and approximate sizes. A short summary establishes a lightweight document map. Summary generation is non-blocking: failure does not discard the body or prevent review.
New and reingested documents enter pending; only ready documents are available to agent retrieval. Administrators review system-scoped documents, while owners manage personal documents. Editing a body reparses its outline and invalidates the previous summary. Incomplete or unconfirmed material therefore cannot enter an answer directly.
A retrieval must satisfy three conditions together:
- The document is
ready. - The current user can see the system or personal document.
- The document belongs to the knowledge set selected for the current task.
Task knowledge selection is an editable resource. A change applies from the next message, while already-produced history remains unchanged.
Knowledge bodies unfold from map to outline to section
aibuddy neither loads every knowledge body at task start nor exposes all low-level knowledge tools directly to the main agent. A built-in knowledge subagent appears only when the capability is available and the task has attached documents. It performs navigation in an isolated context.
| Stage | Internal mechanism | Information exposed | Decision supported |
|---|---|---|---|
| Document map | Task initialization | Title, scope, summary, and section count | Select documents to inspect |
| Document location | read_doc / search_docs | Outline or search hits with section anchors | Identify relevant sections |
| Evidence reading | read_section | One bounded section page, child sections, and a continuation cursor | Read the body required for the answer |
search_docs ranks section-level results across English terms, Chinese characters and bigrams, and quoted exact phrases. It returns one representative hit per section so repeated matching lines do not flood the result. read_section addresses content through stable anchors and pages long sections with a cursor.
Progressive disclosure decouples corpus growth from per-request context cost: the collection can grow while the model expands only material relevant to the current question. The knowledge subagent returns a synthesized answer with document titles and section citations. If the attached corpus does not cover the question, it reports the gap instead of filling it with general knowledge. After retrieval, intermediate bodies can be compacted while document and section pointers remain for traceability.
Design boundaries
- User memory stores stable, user-specific information. It is not an uncited fact store and should not duplicate information recoverable from project files.
- Knowledge stores structured, reviewable source material. It does not implicitly capture user preferences or current task progress.
- Knowledge search uses document structure and ranked terms rather than vector chunks. It prioritizes well-structured internal documents and does not claim to cover every semantic retrieval scenario.
- Knowledge import currently accepts standard Markdown and UTF-8 text. PDF, DOCX, OCR, and other formats require conversion first.
- Memory selection, automatic extraction, and summary generation are auxiliary model paths. Failure falls back to an empty result, lexical recall, or a skipped update without blocking the main task.
Implementation anchors
| Design responsibility | Module |
|---|---|
| Memory records, provenance protection, and recall telemetry | MemoryService |
| Semantic selection over the manifest | memory-recall |
| Automatic extraction, deduplication, and conflict handling | memory-extraction |
| Knowledge publication, visibility, and section retrieval | KnowledgeService |
| Isolated progressive knowledge reading | knowledge-subagent |
These modules compose through narrow interfaces. Changing the persistence implementation or lightweight model does not alter the scope boundary between task context, user memory, and knowledge documents.
Related reading
- User Memory System for memory files, extraction, and privacy boundaries.
- Agent Knowledge Base for document structure, retrieval tools, and the research loop.
- Context Engineering for how memory and knowledge enter active work.