back to Tech

Personal AI bot with: GCP, Code Puppy, and Telegram

•6 min read•Tech

How I turned a GCP cloud VM into an autonomous engineering companion accessible from anywhere via Telegram, powered by Astral uv and Code Puppy.

Building a Headless AI Dev Environment: GCP, Code Puppy, and Telegram

I think that almost everyone in the technology space has dreamed of having their own personal AI agent like Jarvis from the Iron Man movies. Many have done something similar using a Mac Mini running an always-on AI bot. I decided that I didn't want to buy the physical Mac Mini hardware, so I decided to spin up an AI agent running on a virtual machine on Google Cloud Platform. I then created a connector between Telegram, the texting app, and my AI agent. It's not quite like Tony Stark's assistant in the movies, but it is pretty cool to be able to send a text message via Telegram to my AI agent anytime an idea strikes, and it can begin working for me on my Google Cloud instance. This article explains in more detail how I built my bot.

Imagine being away from your workstation—commuting, traveling, or grabbing coffee—and wanting to investigate a bug, ship a quick feature, or execute a complex refactor without opening a laptop.

Juggling SSH clients on mobile devices or tiny on-screen terminals is slow and frustrating. To solve this, I designed and deployed a headless autonomous development environment running on a Google Cloud Platform (GCP) Compute Engine VM, powered by Code Puppy and an outbound Telegram bridge daemon.

Here is how the system is architected, provisioned, and operated.


Architectural Objectives

To create a natural, asynchronous mobile development workflow, the environment needed to meet four core design constraints:

  1. Zero Open Inbound Ports: No public ingress, no open SSH ports facing the internet, and no public webhooks requiring TLS termination or firewall holes.
  2. Persistent Local Workspaces: Real workspaces on disk where git checkouts, node packages, Python virtual environments, and system tools operate natively.
  3. Conversational Telegram Interface: A mobile-friendly chat experience supporting commands (/cd, /status, /diff, /agent), message chunking (respecting Telegram's 4096-character limit), and automated artifact delivery (photos, diagrams, and logs).
  4. Daemonized Reliability: Surviving network drops, long-running agent tasks, and automatic recovery on VM restarts.

High-Level Architecture

+--------------------------------------------------------------+
|                         Telegram App                         |
|                   (Mobile / Desktop Client)                  |
+------------------------------+-------------------------------+
                               | Outbound HTTPS Long-Polling
                               v
+--------------------------------------------------------------+
|                   GCP Compute Engine VM                      |
|                                                              |
|   +------------------------------------------------------+   |
|   |         code-puppy-bridge.service (Systemd)          |   |
|   |                                                      |   |
|   |  - Long-polling daemon (httpx / asyncio)             |   |
|   |  - Concurrency Lock & Workspace isolation            |   |
|   |  - Command Router (/cd, /status, /diff, /agent)      |   |
|   |  - Token & credential redaction sanitizer            |   |
|   +--------------------------+---------------------------+   |
|                              | Subprocess Harness            |
|                              v                               |
|   +------------------------------------------------------+   |
|   |                      Code Puppy                      |   |
|   |  - Installed via Astral uv tool                      |   |
|   |  - Tool execution (ripgrep, file edits, bash shells) |   |
|   |  - Model context orchestration & multi-agent system  |   |
|   +--------------------------+---------------------------+   |
|                              | File I/O & Tool Calls         |
|                              v                               |
|   +------------------------------------------------------+   |
|   |               ~/workspaces/<project>                 |   |
|   |   (Git repositories, Next.js, test suites, builds)   |   |
|   +------------------------------------------------------+   |
+--------------------------------------------------------------+

1. Provisioning the GCP Compute Engine VM

The host runs as an Ubuntu Linux instance on GCP Compute Engine:

System dependencies are installed during provisioning:

sudo apt-get update -y
sudo apt-get install -y git build-essential curl jq ripgrep ca-certificates

2. Fast Python Tooling with Astral uv

Code Puppy is distributed as a modern Python CLI tool. To guarantee rapid installs, deterministic resolution, and clean isolation from the OS system packages, I used Astral uv:

# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install Code Puppy globally in an isolated environment
uv tool install code-puppy --force

Using uv tool install creates an isolated virtual environment dedicated to Code Puppy while placing the executable directly onto the system $PATH.


3. The Telegram to Code Puppy Bridge Daemon

Rather than exposing webhooks to the public internet, the bridge uses Telegram Long-Polling via HTTPX and AsyncIO.

The bridge daemon continuously polls Telegram's getUpdates API. When an authorized message arrives, it handles it in an asynchronous event loop:

Key Adapter Capabilities:


4. Background Persistence with Systemd

To make the environment resilient to VM reboots or network transient failures, the bridge is managed by systemd:

[Unit]
Description=Code Puppy Telegram Long-Polling Bridge Daemon
After=network.target network-online.target
Wants=network-online.target

[Service]
Type=simple
User=appuser
WorkingDirectory=/opt/code-puppy-bridge
EnvironmentFile=/opt/code-puppy-bridge/.env
Environment="PATH=/usr/local/bin:/usr/bin:/bin"
Environment="PYTHONUNBUFFERED=1"
ExecStart=/usr/local/bin/uv run python src/bridge.py
Restart=always
RestartSec=5
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

With sudo systemctl enable --now code-puppy-bridge, the daemon starts on boot and automatically respawns within 5 seconds if an unexpected error occurs.


The Workflow in Practice

With this system in place, building software from a phone is as simple as sending a chat message:

  1. Send /cd my-app in Telegram.
  2. Send: "Add an email subscription component to the homepage that integrates with our transactional email service and triggers an alert on new posts."
  3. The bridge passes the instruction to Code Puppy, which inspects the codebase, creates the database schema migration, writes the components, and verifies the production build.
  4. Telegram responds with real-time progress and a completion summary.
  5. Send /diff to review code changes and git status, and instruct Code Puppy to commit and push.

It transforms an ordinary cloud instance into a personal, always-on AI engineering companion accessible from anywhere.

Personal AI bot with: GCP, Code Puppy, and Telegram — Tech | katabolab blog