mos-agent
v1.2.0
Published
Mos — a lean personal assistant: agent + Zalo gateway + CLI. Install with npm, run with mos.
Maintainers
Readme
Mos
Mos is a personal assistant, written lean from scratch. Python stdlib only (+ Node for the Zalo sidecar), fast to run, easy to deploy for one person.
Install
One command, on Windows, macOS, or Linux (needs Node.js 22+ and Python 3.11+ first):
npm install -g mos-agent
mos --version # mos 1.2.0
mos onboard # first-time setup: keys, channels, self-check
mos tui # full-screen terminal UI (React + Ink, see docs/TUI.md)That installs two commands: mos (the assistant) and mos-zalo
(the Zalo sidecar server). No clone, no virtualenv: the package
carries the whole Mos tree, and the mos launcher finds your Python
and points Mos at the bundled skills from any directory. To try it
without installing: npx -p mos-agent mos --version. Update with
npm update -g mos-agent, remove with npm uninstall -g mos-agent.
See docs/NPM.md and docs/DEPLOY.md
(VPS/cloud with systemd). Releases and CI: docs/CI_CD.md.
What it does
- Chats on your messaging apps — Telegram, Zalo, Discord, Slack, webhook and console, all through one supervisor process.
- Answers with a model, with tools — fast/strong model routing, tool calls (files, web search, Zalo actions, cron, guild admin), long-term memory, and context compression so long sessions stay cheap.
- Stays polite in groups — a two-layer policy gate (admission table + one model assessment) decides whether Mos speaks, watches, or stays quiet.
- Never loses a reply — every reply is written to a durable outbox (SQLite) before it is sent, with retries, ordering per conversation, and a dead letter for failures.
- Runs unattended — per-group fair queues, a worker pool, turn
timeouts, a single-instance guard, and a self-check (
mos doctor).
See docs/flows.html for step-by-step animated flows of how a message travels through Mos, each step citing the real code.
Architecture
%%{init: {"theme": "base", "themeVariables": {"primaryColor": "#e8f5e9", "primaryBorderColor": "#15803D", "primaryTextColor": "#111111", "lineColor": "#15803D", "tertiaryColor": "#ffffff"}}}%%
flowchart LR
subgraph Channels["Channels"]
TG[Telegram]
ZL[Zalo]
DC[Discord]
SL[Slack]
WH[Webhook]
CO[Console]
end
SUP[Supervisor<br/>gateway/supervisor.py]
GATE[Policy gate + attention<br/>policy/gate.py]
AG[Agent<br/>agent/core.py]
ROUTE[Fast / strong routing<br/>agent/routing.py]
MODEL[Model client<br/>agent/models.py]
TOOLS[Tools<br/>tools/registry.py]
OUT[Outbox + effects<br/>gateway/outbox.py<br/>effects.py]
REPLY[Reply to user]
TG --> SUP
ZL --> SUP
DC --> SUP
SL --> SUP
WH --> SUP
CO --> SUP
SUP --> GATE
GATE --> AG
AG --> ROUTE
ROUTE --> MODEL
AG --> TOOLS
TOOLS --> AG
MODEL --> AG
AG --> OUT
OUT --> REPLYThe supervisor polls each channel adapter in its own thread and hands
events to a worker pool (Supervisor.submit / _take_next /
_worker_loop in gateway/supervisor.py). One turn per thread runs at
a time, so a group's history never interleaves. The gate runs before the
agent; the outbox runs after it — the agent itself never sends directly.
Directory structure
agent/ — chat loop (core.py), model client (models.py),
fast/strong routing (routing.py), streaming (streaming.py),
context + memory (context.py, memory_session.py)
tools/ — tool registry (registry.py) + tools: files, web search,
Zalo actions, cron, guild admin, MCP client
policy/ — two-layer gate (gate.py), admission table (admission.py),
mode auto/observe/off (mode.py), assessment (assessment.py)
guild/ — group moderation + Join Guard (moderation.py),
cases (cases.py), teams/attention (team.py)
memory/ — long-term memory store, scoring, graded read caps
session/ — per-thread agent sessions (platform:chat_id)
cron/ — interval cron scheduler + delivery queue
learning/ — turn journal, distill, consolidate, auto-verify
cli/ — the `mos` command (chat / supervisor / status / ...)
doctor.py — `mos doctor` self-check
onboard.py— `mos onboard` interactive setup
effects.py— durable SQLite effects queue (reply delivery, retries)
version.py— the release version (`__version__`)
skills/ — skill code (loader.py, curator.py, hub.py) + 7 bundled skills
plugins/ — plugin host (loader.py)
gateway/ — Supervisor (supervisor.py), outbox (outbox.py),
fair queues (concurrent.py), channel adapters (platforms/)
sidecar/ — Node bridge Zalo (zca-js) <-> Python adapter, local only
+ Zalo MCP server (mcp_zalo_server.js, mock by default)
webui/ — dashboard server (server.py) + bundle (static/)
+ React source (src/, not shipped in the npm package)
config/ — config samples
scripts/ — sidecar runners
tests/ — stdlib tests (pytest)
docs/ — docs, incl. flows.html (animated message flows)Quickstart
# Console chat (no API key needed: without a key it runs in mock mode)
PYTHONPATH=. python3 -m cli.main chat
# Status (never prints API keys)
PYTHONPATH=. python3 -m cli.main status
# First-time setup: answer one question at a time, then self-check
PYTHONPATH=. python3 -m cli.main onboard
PYTHONPATH=. python3 -m cli.main doctor
# (see docs/DOCTOR.md)
# Run all channels in parallel (Telegram, Zalo, Discord, Slack, webhook)
PYTHONPATH=. python3 -m cli.main supervisor --channels telegram,zalo
# (see docs/GATEWAY.md)
# Policy mode: auto | observe | off (live, no restart needed)
PYTHONPATH=. python3 -m cli.main policy mode observe
# List all tools / tail logs (no API key needed, read-only)
PYTHONPATH=. python3 -m cli.main tools
PYTHONPATH=. python3 -m cli.main logs --list
# (see docs/CLI.md)Configure with environment variables: MOS_API_BASE_URL, MOS_API_KEY,
MOS_FAST_MODEL, MOS_STRONG_MODEL, MOS_ZALO_ALLOW_FROM
(see config/config.yaml.example for what each setting means).
Since v0.56, MOS_* keys can also live in ./.env or ~/.mos/.env
(loaded automatically, env already set wins) — that is where
mos onboard stores the provider key; the key is never read from
config.yaml.
Zalo gateway
- In
sidecar/, if running for real:npm install zca-js(mock mode needs nothing). - Start the sidecar:
scripts/run-mos.sh(Windows:scripts/run-mos.bat). The sidecar runs athttp://127.0.0.1:8787, local only, never exposed to the internet. - Open
http://127.0.0.1:8787/login/qrand scan the QR with the Zalo app. The session is saved atsidecar/data/zalo-credentials.json, so you don't need to scan again next time. - In another terminal, run:
mos supervisor --channels zalo(ormos gatewayfor the single-channel legacy gateway).
The Zalo MCP server (sidecar/mcp_zalo_server.js) runs in mock mode
by default — tools only log in memory and return {ok: true, mode:
"mock"}. Real mode needs ZALO_REAL=1 and one QR scan. See
docs/flows.html (flow 9) and docs/ZALO.md.
Docs
- docs/flows.html — animated flows: chat turn, supervisor concurrency, outbox delivery, policy gate, admission, moderation, streaming, onboarding/doctor, Zalo mock vs real.
- docs/DEPLOY.md — deploy with npm / Docker / Compose / systemd.
- docs/NPM.md — the npm package: layout, launcher, publishing.
- docs/MONITORING.md — health endpoint, queues, logs, alerts.
- docs/GATEWAY.md — channels, supervisor, concurrency.
- docs/POLICY.md — gate, admission table, modes.
- docs/OUTBOX_EFFECTS.md — outbox + effects queue.
- docs/STREAMING.md — streaming replies.
- docs/GUILD.md — moderation, Join Guard, cases.
- docs/MODEL_ROUTING.md — fast/strong routing.
- docs/DOCTOR.md —
mos doctorchecks. - docs/CLI.md — full command reference.
- docs/WEBUI.md — dashboard.
- docs/MCP.md — MCP client + Zalo MCP server.
- docs/ZALO.md — Zalo setup and actions.
Limits (stated plainly)
- A dead channel doesn't spread: each adapter runs in its own thread;
an exception in one channel only restarts that thread (backoff 1s →
30s) while the others keep running; failed sends go to dead letter
data/dead_letter/<channel>.jsonlfor later retry (Supervisor.replay_dead_letter). - Isolation is at thread level, not process level — if the whole process
dies, every channel dies with it. One supervisor process only
(
single_instance.pyflock guard). - Per-thread sessions: each
platform:chat_idhas its own agent and history file (data/sessions/); one session cannot read another session's history. Restarting the process starts the agent with empty history (the store still keeps old turns; resuming from the store is not done yet). - At-least-once delivery: if the process dies after
adapter.sendbut beforemark_sent, the message is sent again after restart. No adapter currently accepts an idempotency key. - Python cannot kill a thread: a turn timeout frees the worker and drops the late reply, but the in-flight model call itself keeps running until it finishes.
- Moderation records decisions only — Mos has no kick/ban call on any adapter; human admins do the platform-side removal.
- Text only (DM/groups). Long replies are split per platform limit
(Telegram 4000 chars,
gateway/platforms/telegram.py). - Groups must address Mos to invoke it (default); DMs/groups follow an
allowlist (
MOS_POLICY_ALLOWED_USERS, fail-closed). - Real-mode web search may still parse 0 results from DDG.
- Not yet: voice/image, TUI, native Discord (websocket) Join Guard events; only 17 of 153 Zalo actions are ported (see docs/ZALO_ACTIONS.md).
