Telegram channel
Telegram is the first channel: your agent in a private chat, authenticated, throttled, and approval-capable.
Inbound
Section titled “Inbound”-
Long polling (
getUpdates, 25s timeout). The offset persists in the state store and advances only after dispatch: at-least-once delivery, deduplicated by offset. A crash re-delivers the tail; consumers are idempotent. -
Authentication is the identity table. Private chats only, and the sender’s numeric id must be linked; for messages and button presses. Pairing is a one-time code:
ka-agent pair telegramprints/pair XXXX-XXXXto send to the bot. Unknown senders get no reply; anything they tried shows inka-agent identity pendingwith the exactidentity linkcommand, and lands in the audit chain. The setup wizard offers pairing; the legacyallow_user_idsconfig key migrates into identities at startup. See Matrix & identities. -
Commands route locally, never reaching the engine:
Command Action /start,/helpThe command list. From a linked chat /startis an alias of/helpand ignores a deep-link payload. From an unlinked private chat,/start <payload>redeems the payload as a pairing code (the one-tap form of/pairthatka-agent pair telegramand setup print ashttps://t.me/<bot>?start=<code>): 10-minute TTL, 5 attempts, constant-time compare, a wrong payload answered like a wrong/pair; plain/startfrom an unlinked chat gets the owner hint at most once an hour/statusSession, strand, budgets, queue, memory budget /mode [m]Switch permission mode; from a phone you can only tighten /model [selector],/approvals,/y [id],/n [id]Model (the picker lists what your groups allow), and deciding pending approvals /agent [name]Run this conversation as a shared agent ( /agentalone switches back); see sessions/new [private],/stop,/resumeFresh session ( private: incognito, usage recorded, no text) · abort the running turn · lift a pause/retryRe-send the newest failed or interrupted question (an error the engine marks retryable also offers a ↻ inline button); never automatic /cleanup·/update [check]Delete the bot’s tracked error and notice messages · check for or install the newest release (an install restarts the daemon) /remember,/forget,/memoryStable memory: add, remove, report, candidate review /history <query>Search past turns; /history show <turn_id>/remind,/reminders,/cron,/calendarReminders, scheduled prompts, daily digest /skills,/skill <name> <text>,/skill-doctorOne turn with a skill loaded; skills context cost and attach counts /rules [rm <id>]Durable allow-rules ( /y <id> alwaysadds one; a phone/y <id> alwaysis refused)/plan draft <goal> | list | show | set | approve | run | stopDraft, approve and run a plan with its verify gate /persona,/effort,/undo,/queue,/toolsPersona, session effort, undo the last file change, the waiting queue, the tools on The bot-command menu registers the everyday set, and startup also sets the bot’s profile (the empty-chat description and the chat-list blurb), both best-effort;
/persona,/effort,/undo,/queueand/toolsalso work from the phone but stay out of the menu./quitrefuses from any remote channel: it only ends a local terminal. Any other/wordgetsunknown command /wordplus the hint that/helplists them. Plain text goes to the engine as a prompt. -
Native pickers. A bare
/model,/mode,/effort,/approvals,/queue,/forget,/skillsor/historyfrom a linked private chat answers with one card message carrying an inline keyboard instead of the text listing:/modelopens a provider grid (anthropic (17), the current one dotted, paged) with a model row per vendor,/modeand/effortone row per choice,/approvalsan Allow/Deny row per pending ask,/queuea promote↑and a remove ✕ row per queued message plus Clear all,/forgetpaged forget rows,/skillsthe same accept/reject rows as the proposal cards, and/historypaged turns with a detail row per turn. A bare/cleanupis intercepted the same way but acts directly: it deletes the tracked messages and replies in plain text. Every argument form (/mode <m>,/model <selector>,/skills review,/history <query>, …) still routes through the shared command router unchanged. A press runs exactly what the typed command would: the phone may only tighten a mode press, a loosening one gets the refusal; unknown button data gets an empty answer and no state change, and✕collapses a card to its first line. -
/new privatestarts an incognito conversation from the phone: the reply confirms it (🕶 private session …), inbound media lands underattachments/.private-<short-id>/instead of the shared inbox, and the runtime records usage but no text. See sessions and memory for everything that refuses inside one.
Outbound
Section titled “Outbound”- Streaming. With
telegram.stream(default on), a running reply is pushed as Bot API drafts (stable draft id per turn, plain text, at most 4095 characters, throttled to one request per second and only after 40 new characters; the throttle compares the truncated length, so text that only grows past the cap never re-sends an identical draft). Refusals are classified: 429 flood control is transient and drafts resume afterretry_after; 400/404 (a server that predates drafts) turns drafts off for the process; the turn always ends with the final message. While a turn runs you also get a typing action every 4s plus one editable progress message. - Draft labels. While tools run and no answer text has streamed, the draft shows what is happening (
⋯ running a command echo hi, the same wording every surface uses); the first streamed delta replaces it. Scheduled turns (cron, briefing) never open a draft. - Errors render as cards. An engine error arrives as a structured card: a bold headline, one explanation line, one remedy hint, and the first 300 characters of the raw message escaped (at most 500 characters by construction). When the engine marks the error retryable (its own flag on the error envelope, not a fixed class list) the card carries a
↻ Retryinline button; the press re-submits the stored text of the newesterror/interruptedturn (nothing to retry answersnothing to retry). Never automatic. Cards and notices are tracked: a bare/cleanupdeletes them (removed N message(s); Telegram refuses deletions past 48 h, which is skipped), and any successful turn first deletes the cards tracked before it started, so a failed attempt is cleaned up by its own retry. Tracking is in memory: a restart forgets the ids. In-turn notes strip the engine’s local(esc cancels)hint: Esc does nothing on the phone;/stopis the remote interrupt. - Receipts. Accepted free text gets a 👀 reaction at once, so you know it landed. Callback button presses are answered exactly once; anything this build does not understand gets an empty answer (it only closes the spinner) and no state change.
- Per-user delivery. The surface keeps one chat per linked sender (
telegram:<uid>) and every turn-scoped event carries its source, so a user’s reply goes back to the chat that asked even when several identities share the bot. Escalations (admin approval cards, memory proposals, skill proposals, reminders) go to the admin’s chat; self-scope approval cards go to the asking user’s own chat, and a foreign/y//nis refused and audited. An unlinked sender gets silence; a disabled account also gets silence (no re-pair hint), with onetelegram.unauthorizedaudit row. - Final answers chunk politely: at most 3800 characters per message, split at paragraph boundaries, unbalanced code fences closed per chunk, sends spaced at least 1s apart. A
429sleepsretry_after(clamped to 1..=60s) and retries exactly once; a final chunk that still cannot be sent is requeued in the outbox and redelivered by the startup drain after the next restart (private sessions write no outbox rows). The plain-text fallback for an over-long render splits at paragraph boundaries (hard-break at 4000 characters); notices and error cards are bounded by construction and never split. - Formatted text. Answers are rendered as a Telegram HTML subset (everything escaped first) with
parse_mode: HTML; a parse refusal or an over-long render falls back to plain text.
Turn watchdog
Section titled “Turn watchdog”A turn that is open but silent (the engine is alive and emitting nothing) is a wedge the error classes cannot see. The staged watchdog (turn_watchdog.silent_secs, default 180, and turn_watchdog.abort_secs, default 900; either 0 disables its stage, hot-reload) sends one ⏳ still working notice naming the silence and /stop when the first threshold passes, and aborts the turn exactly like /stop at the second (⏱ no engine activity, naming /retry as the way back). The clock starts when the turn is claimed and any engine event resets it; a pending approval gate is legitimate blocking and never triggers either stage. See configuration.
Self-update from the phone
Section titled “Self-update from the phone”/update runs the same release check, checksum verify and atomic binary swap as ka-agent update; /update check only reports. An install is refused before anything downloads while a turn is in flight (/stop it first: an update restarts the daemon) and when the daemon cannot write its own binary’s directory (a root-owned system install; the reply names ka-agent update on the machine). One install runs at a time, and the release is pinned to the one the daemon validated. Afterwards the daemon stops itself only when a supervisor owns it and no turn started meanwhile, so it comes back on the new binary about 10 s after the reply; otherwise it keeps running the old binary and the reply says exactly which case happened.
Approval, memory, and skill cards
Section titled “Approval, memory, and skill cards”An engine ask renders as: question, the first 20 lines of detail, and an expiry, with an Allow / Deny inline keyboard. A decision answers the engine ask, writes the audit entry, and edits the card to [Approved] / [Denied] / [Expired] with the keyboard removed. A durable always (/y <id> always, like the session form) is terminal-and-web only: from a phone it is refused with the same one-line wording.
When Ka proposes remembering something, you get a memory proposal card: ✅ Remember / ✖ Discard. The press accepts or rejects the candidate and the card edits to its outcome. At most three cards per maintenance tick arrive, plus an “N more” notice.
Skill proposals arrive the same way: a card with ✅ Accept / ✖ Reject, routed through the same /skills accept|reject <id> path as the console. The press installs (or discards) the draft and edits the card to the outcome; a second press of a settled card answers already installed / already rejected and leaves the card alone.
Files, out and in
Section titled “Files, out and in”Files the agent sends you arrive as real files: jpg/jpeg/png/webp up to 10 MB as photos, mp4/m4v/webm/mkv and gif up to 50 MB inline as video or animation (so they play in the chat), everything else as documents (the 50 MB tool cap; the upload gets its own 10-minute timeout). Each send fires a matching upload action first, so the phone shows an upload indicator instead of “typing…”. Captions longer than Telegram’s 1024 characters are truncated before sending, and a failed send falls back to a notice carrying the file’s absolute path.
Photos and files you send (20 MB cap) land in <workspace>/attachments/ with an @reference you can paste back into any message; filenames are sanitized and never overwrite. A caption is your message: the caption is submitted as a full turn (👀 receipt, @reference expansion, engine) with the saved file riding along, so the question is never lost to a bare ack. An album (media group) is saved whole and answered once; unsupported media kinds (video notes, stickers, locations, contacts) get an explicit ! [media] <kind> isn't supported yet reply instead of silence.
Voice notes and audio (20 MB / 10 min) work once a transcriber is configured: ka-agent setup voice (OpenAI or Groq Whisper, or a local Whisper server). The note is transcribed, echoed back as 🎙 "…", and handled exactly like typed text. Without [voice] configured you get one reply naming the command; nothing is submitted.
Secrets
Section titled “Secrets”The bot token never lives in ka-agent.toml; the config names it (token_secret). ka-agent secret set telegram.bot_token writes the 0600 file, and the store also resolves $KA_AGENT_SECRET_TELEGRAM_BOT_TOKEN. The setup wizard asks for the token and verifies it live.
A bad token gets one ! [auth] message to the known chat, then the channel exits. Network errors back off 1s to 60s.