Built for Raspberry Pi · Rust · v0.4.2 · MIT OR Apache-2.0

A tiny agent.
Loyal. Fast. Yours.

Thegan is an AI agent that lives in Telegram and feels at home on a Raspberry Pi: a single static binary, about 2 MB of RAM at idle, no runtime, no database, no Docker.

curl -fsSL https://thegan.klauslochmann.com/install.sh | sh
1.9 MBstatic ARMv7 binary
~2 MBRAM at idle (Pi 3)
0runtimes or databases
5platforms prebuilt

Chat in. Work done.

Message your bot like a colleague. Thegan streams its answer into the Telegram message as it is written, shows a live plain-language status while tools run, and ends every turn with the exact cost.

  • Streaming replies edited into one message, Markdown converted to Telegram HTML.
  • Live status from a cheap utility model while tools are running.
  • Never blocked — /stop works even mid-turn; extra messages are queued.

Made for the Pi in your drawer

Most AI agents want Node, Python, Docker and a gigabyte of RAM. Thegan runs on a Raspberry Pi 3 Model B with 1 GB — and barely notices.

  • One static binary. No runtime, no libc surprises — prebuilt for 32-bit Raspberry Pi OS (ARMv7), 64-bit (arm64) and x86_64.
  • ~2 MB RAM idle. Measured on a Pi 3 Model B running Raspberry Pi OS (Debian 13): about 2 MB resident, 5 threads, near-zero CPU while waiting.
  • No inbound ports. Telegram long-polling goes outbound only — no port forwarding, no dynamic DNS, no TLS certificates.
  • Runs forever. A systemd user unit with linger starts it at boot and restarts it on failure.
  • SD-card friendly. Memory is two small text files; no database writes hammering your card.
  • The model runs in the cloud. Your Pi is the hands, the model provider is the brain — a reply costs a fraction of a cent.

Case: Thegan on a home router →

Small on purpose — perfect for small hardware

Every feature earns its place. Everything else is left to the tools you already trust — Linux, systemd and plain files.

🦀

100% Rust

Only tokio, reqwest, serde and serde_json. No framework, no SDK — the Telegram Bot API and every model provider are hand-rolled.

🔁

Own agent loop

One turn loop with sequential tool calls and a hard max_turns cap, ported from the Pi agent. Easy to read, easy to audit.

🌐

Web search, built in

web_search and web_fetch: Tavily, your own SearxNG, DuckDuckGo or Wikipedia — tried in the order you set. No extra service, and no scraping of the big engines.

🧠

File-based memory

A curated core.md injected every turn plus a searchable log.jsonl. No database, no embeddings — just files you can grep.

📎

Files in, files out

Send a photo, PDF or voice note and Thegan fetches it, saves it and drops its path into the prompt. Images go straight to a vision model — no extra service.

🛡️

Locked to one chat

Only the chat in THEGAN_CHAT may talk to the bot. Stale messages are dropped. State changes need confirmation first.

⏱️

systemd, not a scheduler

Background work is a timer calling thegan --once "…". Nothing to run, nothing to learn, nothing to break.

🔌

Bring your own model

OpenAI, Anthropic, Google or any model OpenRouter offers. One THEGAN_PROVIDER switch, no code changes.

🧾

Honest costs

Each reply ends with provider, model, context fill and the turn's real cost — from the provider's own usage report.

Bring your own model

One internal shape, four vendor APIs. Set THEGAN_PROVIDER and that vendor's key — tool calling, streaming and the status footer behave the same for all of them. The default is OpenRouter, so nothing changes if you do nothing.

THEGAN_PROVIDERKey environment variableExample model
openrouter (default)OPENROUTER_API_KEYdeepseek/deepseek-v4.1-flash
openaiOPENAI_API_KEYgpt-4o-mini
anthropicANTHROPIC_API_KEYclaude-sonnet-4-6
googleGOOGLE_API_KEY or GEMINI_API_KEYgemini-2.5-flash

Set the model with THEGAN_MODEL using the vendor's own model id. Only OpenRouter reports a per-request cost; for the others the footer's $ figure needs THEGAN_PRICE_IN/THEGAN_PRICE_OUT. Endpoints can be redirected with THEGAN_OPENROUTER_URL, THEGAN_OPENAI_URL, THEGAN_ANTHROPIC_URL or THEGAN_GOOGLE_URL.

Running in five minutes

On a Raspberry Pi or any Linux box. You need a Telegram bot token and a model API key — OpenAI, Anthropic, Google or OpenRouter. No Rust toolchain required.

Install

One line, prebuilt static binary for Linux and macOS (x86_64 and arm64), checksum-verified:

curl -fsSL https://thegan.klauslochmann.com/install.sh | sh

Prefer to build it yourself? cargo install --git https://github.com/klauslochmann/thegan works too. Binaries are also on the releases page.

Configure

Create a bot with @BotFather, then put the two secrets and your chat ID into ~/.config/thegan/env.

TELEGRAM_TOKEN=123456:ABC…
OPENROUTER_API_KEY=sk-or-…   # or OPENAI_API_KEY / ANTHROPIC_API_KEY / GOOGLE_API_KEY
THEGAN_CHAT=<your chat id>

Run

Start the listener — or install the provided systemd user unit to keep it running.

thegan --serve
# background job, result pushed to your chat
thegan --once "summarize the last backup log"

All settings are listed in the documentation.

How it compares

Thegan trades breadth for clarity. If you want a multi-channel platform, look elsewhere; if you want a small agent you fully understand, read on.

AspectTheganTypical agent frameworks
ChannelsTelegram onlyMany
Dependencies4 cratesDozens to hundreds
MemoryTwo plain filesDatabase / vector store
Schedulingsystemd timersBuilt-in scheduler
Sub-agentsNone, by designCommon
RAM at idle~2 MB (measured on a Pi 3)Hundreds of MB (Node/Python runtime)
ProvidersOpenAI, Anthropic, Google, OpenRouterMany SDKs

Frequently asked questions

What is Thegan?

Thegan is a minimal AI agent written in Rust that you talk to exclusively through Telegram. It has its own agent loop, eight built-in tools (bash, read, write, edit, grep, memory, web_search, web_fetch), small file-based memory and talks to OpenAI, Anthropic, Google or any model OpenRouter offers. The release binary is under 2 MB on ARM.

Does Thegan run on a Raspberry Pi?

Yes — that is what it is built for. Thegan ships a static 1.9 MB ARMv7 binary for 32-bit Raspberry Pi OS and an arm64 build for 64-bit systems. On a Raspberry Pi 3 Model B it uses about 2 MB of RAM at idle. Install it with: curl -fsSL https://thegan.klauslochmann.com/install.sh | sh

Which Raspberry Pi models are supported?

Any Pi that runs Raspberry Pi OS or another Linux with systemd: Pi 2, 3, 4, 5, Zero 2 W and Pi 400. 32-bit systems use the ARMv7 build, 64-bit systems the arm64 build. The installer picks the right one automatically. The Pi Zero (ARMv6) and Pi 1 are not covered by the prebuilt binaries.

Why the name Thegan?

Thegan is the Old High German word for a retainer or sworn servant — a small, loyal helper. That is exactly the role the agent is designed for.

Which language models can Thegan use?

Thegan speaks to four vendors — OpenRouter (the default), OpenAI, Anthropic and Google. Pick one with THEGAN_PROVIDER and set that vendor's API key; the model is chosen with THEGAN_MODEL. Tool calling, streaming and the status footer work the same for all four. The default is deepseek/deepseek-v4.1-flash via OpenRouter, and a cheaper utility model produces the live status summaries.

Can I send it photos and files?

Yes. Send a photo, document, voice note, audio, video or sticker and Thegan downloads it with getFile, saves it under THEGAN_UPLOAD_DIR, and adds the saved path to the prompt so the agent can open it with its tools. Images are additionally inlined as vision content, so a vision-capable model sees them directly; set THEGAN_VISION=off to send only the path. If a model rejects image input, the turn is retried once without the image.

Can Thegan search the web?

Yes — web_search finds pages and web_fetch reads one. Search runs the backends in the order you set with THEGAN_SEARCH_BACKENDS (default tavily,searxng,duckduckgo,wikipedia) and returns the first that has results: Tavily with TAVILY_API_KEY, a self-hosted SearxNG via THEGAN_SEARCH_URL, or the keyless DuckDuckGo Instant Answer and Wikipedia APIs. It works with no key at all, and gets a real search index once you add Tavily or a SearxNG.

Is Thegan safe to run on my server?

Only the single Telegram chat configured in THEGAN_CHAT may talk to the bot, and stale messages are dropped. Tools run without a permission layer, so you should run it on a machine you trust and never expose it. The system prompt makes the agent ask for confirmation before it changes any state.

How does Thegan remember things?

Memory is two plain files: a small curated profile (core.md) that is injected into every turn, and an append-only searchable log (log.jsonl). Facts are distilled on compaction, on /new and on shutdown. There is no database and no vector store.

Does Thegan have a scheduler or sub-agents?

No. Background work is delegated to systemd: timers call the binary in one-shot mode with thegan --once "<prompt>". There are no sub-agents by design.

What does it cost to run?

The binary itself is free and open source. You pay only for the model usage of the provider you pick. Every reply ends with a status footer that shows the cost of the turn — exact for OpenRouter, which reports it, and derived from your configured prices for the others.

What license is Thegan under?

Thegan is dual-licensed under MIT or Apache-2.0, at your option.

Meet your thegan.

Free, open source and small enough to read in an evening.