100% Rust
Only tokio, reqwest, serde and serde_json. No framework, no SDK — the Telegram Bot API and every model provider are hand-rolled.
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
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.
/stop works even mid-turn; extra messages are queued.you › why is the backup job red? ⚙ Checking the backup log … thegan › The nightly job failed at 03:12: the target disk is 98% full. I can prune snapshots older than 30 days — shall I? you › yes thegan › Done. 14 GB freed, rerun succeeded. anthropic/… · t580 · [#-------] 5.1k/100k 11 s · 3 calls · $0.0042
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.
pi@raspberrypi:~$ curl -fsSL https://thegan.klauslochmann.com/install.sh | sh thegan: downloading thegan-armv7-unknown-linux-musleabihf ... thegan: installed to ~/.local/bin/thegan pi@raspberrypi:~$ systemctl --user enable --now thegan pi@raspberrypi:~$ ps -o rss,cmd -C thegan RSS CMD 2088 thegan --serve
Every feature earns its place. Everything else is left to the tools you already trust — Linux, systemd and plain files.
Only tokio, reqwest, serde and serde_json. No framework, no SDK — the Telegram Bot API and every model provider are hand-rolled.
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 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.
A curated core.md injected every turn plus a searchable log.jsonl. No database, no embeddings — just files you can grep.
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.
Only the chat in THEGAN_CHAT may talk to the bot. Stale messages are dropped. State changes need confirmation first.
Background work is a timer calling thegan --once "…". Nothing to run, nothing to learn, nothing to break.
OpenAI, Anthropic, Google or any model OpenRouter offers. One THEGAN_PROVIDER switch, no code changes.
Each reply ends with provider, model, context fill and the turn's real cost — from the provider's own usage report.
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_PROVIDER | Key environment variable | Example model |
|---|---|---|
openrouter (default) | OPENROUTER_API_KEY | deepseek/deepseek-v4.1-flash |
openai | OPENAI_API_KEY | gpt-4o-mini |
anthropic | ANTHROPIC_API_KEY | claude-sonnet-4-6 |
google | GOOGLE_API_KEY or GEMINI_API_KEY | gemini-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.
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.
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.
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>
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.
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.
| Aspect | Thegan | Typical agent frameworks |
|---|---|---|
| Channels | Telegram only | Many |
| Dependencies | 4 crates | Dozens to hundreds |
| Memory | Two plain files | Database / vector store |
| Scheduling | systemd timers | Built-in scheduler |
| Sub-agents | None, by design | Common |
| RAM at idle | ~2 MB (measured on a Pi 3) | Hundreds of MB (Node/Python runtime) |
| Providers | OpenAI, Anthropic, Google, OpenRouter | Many SDKs |
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.
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
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.
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.
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.
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.
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.
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.
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.
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.
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.
Thegan is dual-licensed under MIT or Apache-2.0, at your option.
Free, open source and small enough to read in an evening.