Thegan › Case: a home router

Thegan on a home router

A Raspberry Pi is a fine home for Thegan — but you may already own something even leaner that never sleeps: your router. This case moves the whole agent from a Linux server onto an OpenWrt box, and keeps it running there.

Why a router?

A router is always on, draws a few watts, and sits behind the same NAT as everything else. Because Thegan only talks outbound — Telegram long-polling, no inbound ports — it needs nothing from the network side. If a 2 MB binary can live in the router's flash, the agent gets a permanent, free home.

The hardware

WhatValue
DeviceCudy / MediaTek Filogic router
OSOpenWrt 25.12.6
CPUARM Cortex-A53 (aarch64), 2 cores
RAM256 MB
Service managerprocd (not systemd)
ShellBusyBox sh (no bash)

What changes when there is no systemd

1 · Pick the right binary

The router is aarch64, so the prebuilt aarch64-unknown-linux-musl release is a drop-in: a static binary with no libc to match.

uname -m                       # aarch64
# thegan-aarch64-unknown-linux-musl.tar.gz  (2.2 MB, static)

2 · Install the binary and config

Copy the binary into /usr/sbin and the secrets into a root-only file, mirroring the systemd layout you already know:

install -m 755 thegan /usr/sbin/thegan
install -m 600 env    /etc/thegan/env   # TELEGRAM_TOKEN, OPENROUTER_API_KEY, THEGAN_CHAT

Durable state (core.md, log.jsonl, the Telegram offset) lives under ~/.local exactly as on any other host, so it can simply be copied across and the agent continues where it left off.

3 · A procd service

The systemd unit becomes a short procd script. set -a exports every variable in the env file, so anything you add there later is picked up without touching the script:

#!/bin/sh /etc/rc.common
# Thegan — minimal Telegram agent, supervised by procd.
USE_PROCD=1
START=95
STOP=10

ENVFILE=/etc/thegan/env
PROG=/usr/sbin/thegan

start_service() {
  [ -r "$ENVFILE" ] || { logger -t thegan "missing $ENVFILE"; return 1; }
  procd_open_instance thegan
  procd_set_param command /bin/sh -c "set -a; . $ENVFILE; exec $PROG --serve"
  procd_set_param env HOME=/root
  procd_set_param respawn 3600 5 5
  procd_set_param stdout 1
  procd_set_param stderr 1
  procd_close_instance
}

Then /etc/init.d/thegan enable starts it at boot and respawn restarts it on failure — the same behaviour as the systemd unit.

4 · Scheduling with cron

Background work, which on systemd was a timer, is a plain crontab line here: an hourly memory curation that does nothing — and costs nothing — when there is nothing to fold.

7 * * * * set -a; . /etc/thegan/env; export HOME=/root;     /usr/sbin/thegan --curate >/dev/null 2>&1

The result

MetricOn the router
Binary2.2 MB, static aarch64
RAM at idle~2.1 MB, 3 threads
Persistent state~44 KB
First reply (one tool call)1.8 s
Cost of that turn$0.0026

An end-to-end turn from the router ran a shell tool (uname -n) and answered in under two seconds. To the chat nothing changed — only the host name in the status footer did.

Takeaway

Thegan's whole design — one static binary, outbound-only networking, files instead of a database — is what makes this possible. There is nothing to containerise and no runtime to install: if a device runs Linux and can reach the internet, the agent can live there.

Back to the documentation →