Trí nhớ
Bestie bắt đầu bằng SQLite memory local. Zep là lớp nâng cao có thể thêm sau, không phải memory layer đầu tiên.
Memory runtime nên tách thành 3 tầng thay vì inject toàn bộ record vào mọi prompt:
| Tầng | Hành vi runtime | Nội dung thường gặp |
|---|---|---|
| Core profile | Luôn inject, nhưng phải rất ít. | Ngôn ngữ ưu tiên, phong cách giao tiếp, identity rules và quyết định bền vững cực quan trọng. |
| Working context | Retrieve theo user, channel, project và query hiện tại. | Project notes, quyết định gần đây, preferences đang active và context trực tiếp cho task. |
| Archive | Vẫn lưu trong SQLite nhưng không inject mặc định. | Record cũ, stale, superseded, raw history và dữ liệu dùng khi search/list/export/cleanup. |
Như vậy toàn bộ memory vẫn có thể xem/search khi cần, nhưng prompt trả lời bình thường không biến thành bãi rác token.
Write policy
Phần tiêu đề “Write policy”| Policy | Hành vi |
|---|---|
allow |
Lưu allowed non-secret memories trực tiếp. |
ask |
Queue memories để owner duyệt. Mặc định. |
deny |
Từ chối memory writes. |
Memory phù hợp để lưu:
- preferences rõ ràng
- project context bền vững
- decisions quan trọng
- cách xưng hô/giao tiếp
- inside jokes hữu ích
Không lưu passwords, tokens, bank details hoặc venting một lần nếu user không yêu cầu.
Lifecycle metadata
Phần tiêu đề “Lifecycle metadata”Mỗi approved memory nên có metadata đủ rõ để recall và cleanup có cấu trúc:
| Field | Ý nghĩa |
|---|---|
layer |
core, working, hoặc archive; quyết định default injection. |
pinned |
Luôn giữ, không auto-clean/consolidate. Dùng cho facts cực quan trọng đã được owner chốt. |
stale |
Nghi ngờ cũ; vẫn searchable nhưng không inject bình thường. |
superseded_by |
Memory này đã bị record mới thay thế. |
last_accessed_at |
Lần cuối memory được retrieve. |
access_count |
Memory hay dùng thì có tín hiệu giữ gần hơn. |
confidence |
Agent chắc bao nhiêu rằng memory này đúng và còn hiệu lực. |
expires_at hoặc ttl |
Context tạm thời tự hết hạn. |
Pinned core memories phải hiếm. Phần lớn memory nên nằm ở working context hoặc archive.
Scoring trước khi inject
Phần tiêu đề “Scoring trước khi inject”Mỗi request nên score memory trước khi build prompt. Các tín hiệu chính:
- semantic relevance với query hiện tại
- match user/channel/project
- recency
- access count
- confidence
- pinned/core status
- stale/superseded/expired state
Prompt assembly nên theo thứ tự:
- Inject core profile records đã approved, nhất là pinned records.
- Retrieve và inject top working-context memories liên quan nhất.
- Không inject archive trong flow trả lời bình thường.
- Chỉ dùng archive khi user gọi
/memory, search/list/export/cleanup hoặc khi agent chạy memory doctor.
/memory, bestie memory list và internal list tools vẫn nên trả được toàn bộ records. Khác biệt nằm ở prompt runtime: không nuốt toàn bộ SQLite history.
Commands
Phần tiêu đề “Commands”bestie memory statusbestie memory pausebestie memory resumebestie memory listbestie memory list --scope corebestie memory tiersbestie memory summarybestie memory search concisebestie memory add communication_preference "User prefers concise replies."bestie memory inspect 1bestie memory edit 1 "Updated memory text."bestie memory pin 1bestie memory unpin 1bestie memory move 1 --scope projectbestie memory supersede 1 2bestie memory forget 1bestie memory messages --limit 5 --role userbestie memory messages search project --limit 5 --role assistantbestie memory exportbestie memory clear --yesbestie memory pendingbestie memory pending search hanoi --limit 5bestie memory pending inspect 1bestie memory approve 1bestie memory reject 1bestie memory reject-all --yesbestie memory list --scope nhận core, project, hoặc session. pin, unpin, move, và supersede chỉnh lifecycle metadata của memory đã có.
Memory doctor và cleanup
Phần tiêu đề “Memory doctor và cleanup”Memory doctor nên báo report có cấu trúc:
- duplicate groups
- contradictory memories
- stale memories
- low-value noisy memories
- pinned/core memories
- memories thiếu metadata
Cleanup nên consolidate trước khi delete:
- Gom memory giống nhau.
- Phát hiện mâu thuẫn.
- Merge nhiều memory vụn thành một memory rõ hơn.
- Đánh dấu record cũ bằng
superseded_by, archive hoặc soft-delete. - Chỉ delete khi policy cho phép.
Ví dụ:
User prefers Vietnamese.User wants Vietnamese-first.Always answer in Vietnamese with diacritics.Có thể consolidate thành:
User prefers Vietnamese replies with proper diacritics unless they ask for another language.Các lệnh kiểm tra và cleanup hiện có:
bestie memory analyzebestie memory analyze --mode duplicatesbestie memory analyze --mode stalebestie memory analyze --mode conflictsbestie memory cleanup --dry-runbestie memory cleanup --apply --yesbestie memory hygienebestie memory hygiene statusbestie memory hygiene doctorbestie memory hygiene doctor --fixbestie memory hygiene trendbestie memory hygiene --apply --yesbestie memory rebalance --dry-runbestie memory rebalance --apply --yescleanup, hygiene --apply, và rebalance --apply tôn trọng memory.deletePolicy. Nếu policy là deny, Bestie từ chối. Nếu policy là ask, dùng --yes sau khi review plan.
Maintenance và governance
Phần tiêu đề “Maintenance và governance”Memory maintenance report là cron-backed check để Bestie tự chạy phân tích memory và gửi report định kỳ:
bestie memory maintenance install --channel telegram:123456789bestie memory maintenance install --channel zalo:123456789 --schedule "0 9 * * 1"bestie memory maintenance statusbestie memory maintenance removebestie memory digestbestie memory digest chạy report ngay từ CLI. Governance điều khiển độ rộng retrieval:
bestie memory governance statusbestie memory governance policy fullbestie memory governance policy governedNguyên tắc
Phần tiêu đề “Nguyên tắc”Memory phải làm Bestie hữu ích hơn, không làm user thấy bị theo dõi. Over-remembering là bug sản phẩm.
