Using Pi as a VPS Admin: Chat With Your Server via Telegram

In this tutorial, I show how I use a Raspberry Pi agent as my always-on VPS administrator. When my main Hermes agent breaks, I have a backup Pi agent running on the same server that I can chat with via Telegram to fix issues, manage services, and update configurations without ever opening a terminal.

Why a Backup Admin Matters

If you run AI agents on a VPS, you have probably experienced the frustration of your main agent breaking. When that happens, you typically need to SSH into the server, check logs, restart services, and debug the problem manually.

I solve this by running a second Pi agent directly on the VPS. This agent persists independently of my main Hermes agent, so even when Hermes is down, Pi is still there to help.

How the Telegram Gateway Works

The bridge between Telegram and the Pi agent is a lightweight tool called PyGateway. It runs as a daemon on the VPS and does three simple things:

  1. Listens for messages on a Telegram bot
  2. Forwards those messages to the Pi agent via RPC
  3. Sends the agent’s responses back to Telegram

This means you can manage your server from anywhere. You do not need to be at your computer or have an SSH client ready. You just send a message.

Setting Up PyGateway

PyGateway is open source and easy to install:

pip install pygateway
pyagent configure telegram

During configuration, you will set your Telegram user ID and the workspace directory. After that, the gateway runs continuously in the background.

You can run it in the foreground for testing:

pyagent gateway --foreground

Or daemonize it for production use.

What You Can Do With It

Once the gateway is running, your Pi agent becomes a full VPS admin accessible through chat. Here are some of the things I use it for:

  • Restart services when Hermes crashes
  • Check logs to diagnose errors
  • Update firewall rules to open or close ports
  • Reconfigure Caddy to expose new web apps or domains
  • Monitor disk space, memory, and CPU usage

It is like having a system administrator on call, except the admin is an AI agent that responds instantly.

Keeping a Living Config Wiki

One of the most useful tricks I have learned is prompting Pi to maintain a server configuration wiki. Every time the agent changes something on the server, it documents the change in a markdown file.

For example, if Pi opens a new port or adds a Caddy endpoint, it updates the wiki with:

  • What changed
  • Why it changed
  • When it changed

This prevents configuration drift and means you always have an up-to-date record of your server state. No more guessing what ports are open or what services are running.

References