Overview
Upsonic’s AutonomousAgent is wired to Telegram via TelegramInterface in CHAT mode so it keeps conversation context. The stack is minimal:- AutonomousAgent — LLM-driven agent with filesystem and shell tools, sandboxed to a workspace directory
- Workspace — Agent’s home: AGENTS.md (playbook), SOUL.md (identity), USER.md (who you are), MEMORY.md (long-term),
memory/YYYY-MM-DD.md(daily logs) - Telegram — Chat UI; webhook receives updates, FastAPI serves the webhook
- ngrok — Exposes localhost so Telegram can reach your bot
backups/ with a fixed naming pattern), incident response (severity, evidence, log to memory). It prefers trash over rm, never pipes unknown input to bash, and asks before editing app code or restarting services.
Project Structure
Environment Variables
Configure the bot and LLM via environment variables (e.g. in.env):
Installation
Option A: Setup script.env from .env.example and set TELEGRAM_BOT_TOKEN, TELEGRAM_WEBHOOK_URL, and OPENAI_API_KEY.
Usage
1. Create the Telegram bot and get your user ID
- In Telegram, open @BotFather →
/newbot→ choose name (e.g. “DevOps Agent”) and username. - Copy the bot token.
- Open @userinfobot → send any message → copy your user ID (optional, for
TELEGRAM_USER_ID).
2. Expose localhost with ngrok
https://xxxx.ngrok-free.app URL into .env as TELEGRAM_WEBHOOK_URL.
3. Run the bot
0.0.0.0:8000. Telegram will send updates to your webhook URL.
Demo commands (send in Telegram)
| Message | What the agent does |
|---|---|
Check disk usage | Runs df -h in workspace context, returns formatted result |
Find all log files larger than 50KB | Searches workspace, lists matching files |
Create a backup of the app directory | Tars app/ into backups/ with playbook naming, confirms |
Read the last 20 lines of error.log and tell me what's wrong | Reads log, analyzes, summarizes |
List all running processes using port 8000 | Runs shell command, returns results |
Show me the app config | Reads config.yaml, explains it |
How It Works
| Component | Description |
|---|---|
| AutonomousAgent | Upsonic agent with filesystem + shell; loads workspace (AGENTS.md, SOUL.md, USER.md, memory) and runs in CHAT mode |
| TelegramInterface | Webhook-based Telegram bot; CHAT mode keeps conversation context; optional TELEGRAM_USER_ID lock |
| InterfaceManager | Serves FastAPI app that receives Telegram webhook and dispatches to the agent |
| Workspace | Sandbox root: all file/shell operations stay under this directory |
| AGENTS.md | Playbook: session startup, memory rules, safety, DevOps procedures (logs, system checks, backups, incidents), group-chat behavior |
| SOUL.md / USER.md | Identity and user context loaded every session |
| MEMORY.md / memory/ | Long-term and daily memory for continuity across sessions |
Example flow
- User sends “Check disk usage” in Telegram.
- Telegram hits your webhook → FastAPI → TelegramInterface.
- Interface passes the message to AutonomousAgent.
- Agent (with workspace context) uses its tools to run the appropriate command (e.g. shell or read), then replies.
- Reply is sent back to Telegram.
Complete Implementation
bot.py
workspace/ (AGENTS.md, SOUL.md, USER.md, MEMORY.md, memory/, logs/, app/, backups/).
Workspace and Agent Behavior
- SOUL.md — Defines the agent as “DevOps Agent”, a senior systems engineer: fast, direct, technical; treats the workspace as the server.
- USER.md — Describes the human as a developer/DevOps who wants quick answers from Telegram without SSH.
- AGENTS.md — Full playbook: read SOUL, USER, and memory each session; use
memory/YYYY-MM-DD.mdand MEMORY.md for continuity; safety rules (no exfiltration, no destructive commands without asking,trashoverrm); DevOps procedures for logs, system checks, backups, incidents; when to speak in group chats and how to react. - MEMORY.md — Long-term: server baseline, known issues (e.g. Redis instability, DB performance), patterns to watch, useful commands, app structure. Loaded in main session only (not in shared/group contexts).
- memory/YYYY-MM-DD.md — Daily log: session start, health checks, issues found, actions taken. Agent creates/updates these.
workspace/app/ and workspace/logs/ provide sample app code and logs so the agent can demonstrate backups, config reading, and log analysis without touching real production.
Key Features
Sandboxing
- The agent is restricted to the workspace directory. File and shell operations outside it are blocked.
- Use TELEGRAM_USER_ID so only your account can talk to the bot.
CHAT mode and memory
- InterfaceMode.CHAT keeps conversation context so the agent can do multi-turn tasks.
- /reset (configurable) clears conversation state.
- Memory is file-based: daily logs in
memory/and long-term in MEMORY.md, so behavior is reproducible and auditable.
DevOps playbook (AGENTS.md)
- Log analysis: Check size first, use tail/grep/wc, count by type, summarize and recommend.
- System checks: Run df/free/ps, flag anomalies (e.g. disk >80%, low memory).
- Backups:
tar -czftobackups/, name like{what}-backup-{YYYY-MM-DD-HHMM}.tar.gz, log to daily memory. - Incident response: One-line summary, severity (🔴/🟡/🟢), evidence, suggested fix, log to daily memory.
Platform-aware output
- Telegram: short messages, monospace for commands/output.
- Group chats: respond when relevant (e.g. mentioned or troubleshooting); avoid dominating or over-reacting.
Security Notes
- Agent is sandboxed to
workspace/; no access to the rest of the host by default. - Set TELEGRAM_USER_ID to restrict the bot to your Telegram account.
- AGENTS.md instructs the agent not to exfiltrate private data, not to run destructive commands without asking, and to avoid piping unknown input to bash or eval.

