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

Kiến trúc

Bestie là runtime local-first, tự host được. Cùng một runtime core phục vụ terminal chat, Telegram, Zalo, UI local tương lai, MCP và các extension sau này.

User / Channel
-> Channel Adapter
-> Runtime Orchestrator
-> Mode Detector
-> Memory Router
-> Prompt Builder
-> LLM Adapter
-> Safety / Permission Layer
-> Tool / Plugin / MCP Router
-> Response
-> Logs + Memory Update

CLI sở hữu các lệnh user-facing:

  • onboard
  • chat
  • status
  • logs
  • doctor
  • memory
  • telegram
  • zalo
  • tools
  • mcp

Telegram là channel đầy đủ đầu tiên: polling local, owner-only, slash commands, typing indicators, progress edits, attachments, memory controls, Doctor summaries và approval prompts.

Zalo hiện là adapter text-only giai đoạn đầu: polling local, owner-only, slash commands, typing indicators, tách reply dài, memory controls, provider diagnostics, approval prompts, transcript logging và capture response shape để debug tích hợp. Attachments, voice, rich templates và webhook hosting chưa nằm trong adapter Zalo đầu tiên.

CLI nên gọi runtime services, không duplicate business logic.

Một turn đi qua các bước:

  1. Nhận message từ terminal, Telegram hoặc adapter khác.
  2. Load config, env, character files và memory context.
  3. Build prompt.
  4. Resolve LLM profile và model ref đang active, rồi gọi provider adapter đã cấu hình.
  5. Chạy tool loop nếu được phép.
  6. Gửi response.
  7. Lưu logs đã redact và memory updates được duyệt.

Bestie load character từ file local như character.json, system-prompt.md, style examples và safety boundaries.

Mục tiêu là một AI best friend có cá tính: hài, thẳng, biết quan tâm, có thể phản biện nhưng không hạ nhục người dùng.

Memory hiện tại dùng SQLite local. Nó lưu approved memories, pending memories, lifecycle metadata, terminal/Telegram messages, pause state và pending approvals.

Memory được tách thành 3 tầng:

  • Core profile: rất ít memory luôn được inject, ví dụ 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: memory liên quan trực tiếp tới user, channel, project và query hiện tại; được retrieve theo lượt.
  • Archive: record cũ, stale, superseded hoặc ít ưu tiên vẫn nằm trong SQLite để search/list/export/cleanup, nhưng không inject mặc định.

Prompt builder nên inject core profile, score và retrieve top working-context records, còn archive chỉ dùng khi có lệnh search, list, export hoặc cleanup rõ ràng. Lifecycle metadata như pinned, stale, superseded_by, last_accessed_at, access_count, confidenceexpires_at giúp cleanup/consolidation có cơ sở thay vì đọc text rồi đoán.

Zep có thể được thêm sau như lớp memory nâng cao, nhưng không nên thay thế character files hoặc memory controls local.

Mọi hành động ngoài text reply nên được phân loại:

  • read-only
  • local write
  • external write
  • public action
  • destructive
  • money/payment
  • unknown

Bestie bắt đầu với internal read tools và MCP read-only đã classify. Các hành động rủi ro hơn cần permission UX, logs và approval rõ ràng.