capri-memory: add README
This commit is contained in:
1 file changed
+66
@@ -0,0 +1,66 @@
|
||||
# capri-memory
|
||||
|
||||
Long-term memory of Capri.
|
||||
|
||||
| Module | Capri source | Role |
|
||||
|---|---|---|
|
||||
| `notes` | `owner-notes.mjs` | "remember that my X is Y" fast path, `memory/capri-owner-notes.md`, recall without a model |
|
||||
| `index`, `embed` | OpenClaw memory-core, `embedding-model.mjs` | `<data>/agent/memory.sqlite`: chunks, FTS5, bge-m3 vectors, hybrid search |
|
||||
| `tools` | OpenClaw `memory-tool-contract`, `read-file` | `memory_search`, `memory_get` |
|
||||
| `saved` | `saved-memory.mjs`, `memory-controls.mjs` | saved-memory viewer, "Clear long-term memory" |
|
||||
| `private` | `private-memory.mjs`, `private-dialogue.mjs` | password vault (scrypt + AES-256-GCM, Capri file format), private chat |
|
||||
| `brain` | `brain-knowledge.mjs`, `brain-worker.mjs` | `<data>/brain` documents → `<data>/desktop/brain.sqlite` (Capri schema) |
|
||||
| `compaction` | `context-policy.mjs`, `context-fallback.mjs`, OpenClaw safeguard | budget constants, five-heading summary, audit, extractive fallback |
|
||||
| `ui` | `saved-memory-panel`, `knowledge-panel`, `private-memory-panel` | plain egui settings pages |
|
||||
|
||||
Files: `<data>/agent/memory.sqlite` (derived, safe to delete), `<data>/brain/`, `<data>/desktop/brain.sqlite`,
|
||||
`<data>/desktop/private-memory.enc.json` (+ `.bak`), `<ws>/memory/capri-owner-notes.md`.
|
||||
|
||||
## Integration
|
||||
|
||||
### Start
|
||||
|
||||
```rust
|
||||
let memory: capri_memory::MemoryHandle = capri_memory::MemoryService::start(store.clone)?; // inside the Tokio runtime
|
||||
```
|
||||
|
||||
`start` opens the stores and spawns the background loop: sync at startup, re-index 1.5 s after a memory file
|
||||
changes, embeddings retried once a minute while Ollama or `capri-embed:latest` is missing, Brain folder re-indexed
|
||||
when it changes, private vault locked after 5 minutes idle. Embeddings use the conversation Ollama
|
||||
(`Settings::ollama_base_url`); `capri-embed:latest` is created from `bge-m3:latest` when that model is present.
|
||||
Without it, `memory_search` answers in `keyword-only` mode with a warning.
|
||||
|
||||
### Engine (capri-agent)
|
||||
|
||||
| When | Call |
|
||||
|---|---|
|
||||
| building the tool list | `memory.tools` → `memory_search`, `memory_get` (`Vec<Arc<dyn Tool>>`) |
|
||||
| before any model work, text turn without mode | `capri_memory::owner_note_request(text)`: `Save(note)` → `memory.save_note(¬e)`, reply `notes::REPLY_SAVED` (translated) or `notes::reply_failed(lang)`; `Refused` → `notes::reply_refused(lang)`. Otherwise `memory.recall_note(text)`: `Some(v)` → reply `v`. Journal only, no session entry, `followUp=false` |
|
||||
| building the per-turn envelope | append `memory.knowledge_context(&text, remote)` after desktop state / observation |
|
||||
| after each committed turn | `memory.on_session_messages(n_messages, n_bytes)` (re-index after 50 messages or 100 kB) |
|
||||
| after a compaction or `reset_conversation` | `memory.after_compaction` |
|
||||
| preflight / compaction | `compaction::turn_output_budget`, `compaction::context_policy(ctx, budget)`, `compaction::estimate_tokens`, `compaction::find_cut_point(&view, policy.keep_recent_tokens)` (None → `CONTEXT_COMPACTION_FAILED` + `NO_RECENT_MESSAGE_FITS`) |
|
||||
| compacting | `compaction::compact(CompactRequest { messages, previous_summary, latest_unresolved_request, max_input_chars, max_summary_chars }, \|msgs\| llm(msgs)).await` → summary; store it in a `compaction` entry and send `compaction::summary_message(&summary)` first in the model view. The closure must call the model with `think:false`, `num_predict = policy.summary_max_tokens`, 10 s no-progress timeout. |
|
||||
| mid-run recovery | `compaction::CONTINUATION_PROMPT`, `compaction::TOOL_FAILURE_INSTRUCTION` |
|
||||
| system prompt (with memory tools) | OpenClaw "## Memory Recall" section is not ported here; see "Not done" |
|
||||
|
||||
Session indexing reads `<data>/agent/session.sqlite` (`sessions`, `entries` of `capri_agent::session`) read-only:
|
||||
user/assistant `content` with the per-turn envelope (`\n\nDESKTOP STATE FOR THIS TURN`, `\n\n[Read-only screen
|
||||
observation`, `\n\n[Local Brain excerpts`, `\n\nCURRENT WEB SEARCH`) and `[avatar:…]` markers removed.
|
||||
Keep that schema and those markers stable, or tell this crate.
|
||||
|
||||
### App / Settings window
|
||||
|
||||
- `capri_memory::settings_ui(ui, &store, &memory)`: Memory (remember across conversations, saved memories, add a
|
||||
fact, clear long-term memory with confirmation), Brain (enable, share with API, folder, refresh, documents
|
||||
add/remove, test search), Private memory (create/unlock/lock, notes, private conversation, change password).
|
||||
- When the Settings window hides: `memory.on_settings_hidden` (locks the vault, wipes private fields).
|
||||
- Settings section: `memory` → `MemorySettings { rememberAcrossConversations: true, brainEnabled: true, brainShareWithApi: false }`.
|
||||
|
||||
## Not done
|
||||
|
||||
- OpenClaw prompt section "## Memory Recall" (`buildMemoryPromptSection`) belongs to the engine's prompt assembly.
|
||||
- Memory extraction (automatic MEMORY.md/USER.md writing) is not implemented.
|
||||
- Private chat over an external API (`allowApi`): Rust only has local Ollama, so the option is absent.
|
||||
- Brain uses keyword (FTS5) retrieval exactly like Capri; no embeddings.
|
||||
- Editing or deleting a single saved fact: Capri has no such action (only add, view, clear all).
|
||||
Reference in new issue
Block a user