Bỏ qua để đến nội dung

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.

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.

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.

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ự:

  1. Inject core profile records đã approved, nhất là pinned records.
  2. Retrieve và inject top working-context memories liên quan nhất.
  3. Không inject archive trong flow trả lời bình thường.
  4. 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.

Terminal window
bestie memory status
bestie memory pause
bestie memory resume
bestie memory list
bestie memory list --scope core
bestie memory tiers
bestie memory summary
bestie memory search concise
bestie memory add communication_preference "User prefers concise replies."
bestie memory inspect 1
bestie memory edit 1 "Updated memory text."
bestie memory pin 1
bestie memory unpin 1
bestie memory move 1 --scope project
bestie memory supersede 1 2
bestie memory forget 1
bestie memory messages --limit 5 --role user
bestie memory messages search project --limit 5 --role assistant
bestie memory export
bestie memory clear --yes
bestie memory pending
bestie memory pending search hanoi --limit 5
bestie memory pending inspect 1
bestie memory approve 1
bestie memory reject 1
bestie memory reject-all --yes

bestie 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 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:

  1. Gom memory giống nhau.
  2. Phát hiện mâu thuẫn.
  3. Merge nhiều memory vụn thành một memory rõ hơn.
  4. Đánh dấu record cũ bằng superseded_by, archive hoặc soft-delete.
  5. 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ó:

Terminal window
bestie memory analyze
bestie memory analyze --mode duplicates
bestie memory analyze --mode stale
bestie memory analyze --mode conflicts
bestie memory cleanup --dry-run
bestie memory cleanup --apply --yes
bestie memory hygiene
bestie memory hygiene status
bestie memory hygiene doctor
bestie memory hygiene doctor --fix
bestie memory hygiene trend
bestie memory hygiene --apply --yes
bestie memory rebalance --dry-run
bestie memory rebalance --apply --yes

cleanup, 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.

Memory maintenance report là cron-backed check để Bestie tự chạy phân tích memory và gửi report định kỳ:

Terminal window
bestie memory maintenance install --channel telegram:123456789
bestie memory maintenance install --channel zalo:123456789 --schedule "0 9 * * 1"
bestie memory maintenance status
bestie memory maintenance remove
bestie memory digest

bestie memory digest chạy report ngay từ CLI. Governance điều khiển độ rộng retrieval:

Terminal window
bestie memory governance status
bestie memory governance policy full
bestie memory governance policy governed

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.