What It Provides
- Channel: A GrammY-based Telegram bot that routes user messages to agents and supports concurrent sessions per thread
- Tool:
telegramcommand for agents to send proactive messages
Configuration
Add to yourconfig.json5:
Prerequisites
- Create a Telegram bot via @BotFather
- Get your bot token
- Get your Telegram user ID (message @userinfobot)
Bot Commands
Users interact with the bot via these commands:Switching Agent or Model
Both/agent and /model change the current session without losing history:
- The
.jsonlconversation file is kept on disk untouched - Only the in-memory pi session is disposed and recreated
- The next message picks up from the same history with the new agent/model
/agent <name>Switches to a different configured agent. The new agent’s system prompt, tools, and skills apply from the next message. Useful for routing the same conversation to a specialist agent mid-task.
/model provider/modelIdSwitches to any model in the current agent’s allowed list (primary or fallback). The model must be listed under the agent’s
model or fallbackModels config.
/new clears them (starting fresh resets to the agent’s default).
Message Reactions
The bot reacts to every user message to communicate processing state:
Reactions are set via the Bot API’s
setMessageReaction. They are silently skipped if the bot lacks reaction permissions in a channel or if the chat type doesn’t support them (e.g. some supergroups).
Steering messages (sent while the agent is already running) get 👀 but not 🎉 — they don’t own the session lifecycle.
Concurrency & Steering
The plugin is fully non-blocking: the grammY handler returns immediately and sessions run as background tasks. This means:- Multiple threads run in parallel — each chat/thread has its own session and they operate independently, simultaneously
- Sending a message while the agent is running steers it — exactly like pressing ESC in the TUI. The new message is injected as a steering interrupt; the agent finishes its current tool call, then processes your message. No need to wait or use
/stopfirst /stopfor hard abort — immediately aborts the current operation (LLM call + tool loop). The partial response (if any) is sent before the stop confirmation
/status Output
/status shows the current model, context window usage, and settings:
/compact — Manual Compaction
Manually compresses the conversation history using an LLM summarisation pass:
- If a session is active when
/compactis called, it is aborted first (built-in to pi’s compaction) - Works after a gateway restart — the session file is reloaded from disk automatically
- Shows tokens freed and the post-compaction context bar on success
Auto-Compaction Notifications
When the agent automatically compacts the context (threshold or overflow recovery), the bot sends a notification:🗜️ Auto-compacting context…when it starts✅ Context auto-compacted (~Xk tokens).on success- For overflow recovery:
✅ Context auto-compacted (~Xk tokens). Retrying your request…
Error Handling
LLM errors (invalid API key, rate limits, model unavailable, etc.) are forwarded to the chat with user-friendly messages:Tool Usage
Agents can send messages proactively:Session Model
- Each Telegram chat gets a persistent session (survives gateway restarts)
- Forum topics (threads) each get their own independent session
/newstarts a fresh session; old conversation is preserved on disk- Verbose and streaming settings are persisted per-session
/compactand/statuswork even after a gateway restart — sessions are lazily restored from disk on demand
