High-Level Diagram
Components
Daemon
The persistent
max start process. Owns the Copilot SDK client, orchestrator session, HTTP API server, and Telegram bot. All other interfaces connect to it.TUI
A lightweight terminal client (
max tui) that connects to the daemon over localhost SSE. No AI logic runs here — it’s a display and input layer only.Orchestrator
A single, long-running Copilot SDK session. It receives every message, routes it to the right model, executes tools, and streams responses back to the caller.
Workers
Temporary Copilot CLI sessions spawned on demand for coding tasks, file operations, and command execution. Up to 5 run concurrently; each is destroyed after completing its task.
HTTP API
An Express server on port 7777. Exposes
POST /message, GET /stream (SSE), GET /sessions, GET /memory, GET /skills, and more. Authentication via bearer token stored in ~/.max/api-token.Telegram Bot
Optional remote interface using the grammy library. Authenticated by a single authorized user ID — all other senders are silently ignored.
Data Flow
Message arrives
A message arrives from Telegram, the TUI (via
POST /message), or a background worker completion. It is tagged with its source channel ([via telegram], [via tui], or left untagged for background).Enqueued
The tagged message is pushed onto the
messageQueue. The queue is processed one entry at a time — if the orchestrator is busy, new messages wait rather than interleaving.Model resolved
Before execution,
resolveModel() runs. In auto mode it classifies the message as fast, standard, or premium and selects the appropriate model. Keyword-based overrides (e.g. design tasks) take precedence. If the model changes, the orchestrator session is destroyed and recreated.Orchestrator executes
session.sendAndWait() runs with a 300-second timeout. As the model streams its response, assistant.message_delta events accumulate and are forwarded to the caller’s callback in real time.Tools fire
If the model calls a tool (e.g.
create_worker_session, remember), the tool handler runs synchronously inside the sendAndWait call. Worker tasks are dispatched in the background and return immediately.Deployment Model
Max is designed as a single-machine, single-user daemon. All data stays on your machine — there is no cloud sync, no remote database, and no multi-user support.
| Property | Detail |
|---|---|
| Process model | One persistent daemon (max start) |
| AI runtime | GitHub Copilot SDK (auto-started if not running) |
| Networking | Localhost only (127.0.0.1:7777) for the API; Telegram uses outbound polling |
| Persistence | SQLite at ~/.max/max.db |
| Copilot config | Reads ~/.copilot/mcp-config.json for MCP servers |