A multi-agent system that lets a local LLM running on Ollama search, explore, and reason over your Telegram: your own chats, groups, channels, the public channel directory, and arbitrary links inside messages. No cloud, no vendor, no content filtering.
Designed around an agent harness (ReAct + JSON tool-calling) plus a
multi-agent orchestrator that can spawn focused sub-agents
(dialog_search, channel_explorer, link_crawler, generic).
An optional MCP server exposes every tool to Cursor / VS Code Copilot.
- Uses MTProto (Telethon): the agent has the same reach as your own Telegram
app: DMs, groups, joined channels, public channel directory, joining new
channels, and resolving / following
t.me/...links. - Multi-agent:
orchestratorplans, dispatchesspawn_subagentcalls to specialists, then synthesises the result. - Hybrid local index: SQLite FTS5 BM25 + Ollama embeddings
(
qwen3-embedding:0.6bby default) with cosine similarity, fused with min-max normalised scores. - Web tool:
http_fetchfor non-Telegram links found in messages, routed through your local proxy. - Optional vision:
qwen3.5already has built-in vision, so by defaultVISION_MODELpoints at the sameqwen3.5model and the agent can calltg_describe_mediaon photos/videos it finds. - MCP server: expose the whole tool belt to Cursor / Copilot Chat.
- Windows / Linux / macOS
- Python >= 3.10 (conda / venv / pixi all work)
- Ollama running locally at
127.0.0.1:11434 - A Telegram account + API id/hash from https://my.telegram.org
- Local proxy at
127.0.0.1:7890(Clash-style HTTP proxy)
Qwen3.5 (released April 2026) has tool-calling, vision, and thinking mode in one model, which is exactly what this system needs. The default setup uses the Qwen3.5 family throughout and does not require a separate vision model.
| Role | Pick | ~VRAM (Q4) |
|---|---|---|
| Default / low VRAM | qwen3.5:0.8b |
~1 GB |
| Balanced / 8GB GPU | qwen3.5:4b |
~3 GB |
| Best for 3060 12GB | qwen3.5:9b |
~5-6 GB |
| Embeddings | qwen3-embedding:0.6b or bge-m3 |
tiny |
| Heavy-duty (24GB+) | qwen3.6:35b or qwen3:30b |
~15-20 GB |
Pulls:
ollama pull qwen3.5:0.8b
ollama pull qwen3-embedding:0.6bIf you want image understanding, point VISION_MODEL=qwen3.5:0.8b in .env.
That reuses the same weights with zero extra VRAM.
conda activate <your-env> # or activate your venv
cd /path/to/Rewind.tg
pip install -r requirements.txt
copy .env.example .env
notepad .env # fill TG_API_ID / TG_API_HASH / TG_PHONE, tweak modelsFirst login (interactive; saves data/tg.session):
python -m tg_search.telegram_clientEnter the SMS / app code, and your 2FA password if enabled. The session is reused after that.
python cli.py "find every message mentioning 'stable diffusion LoRA' across all my chats, summarise the top 10 with links"python cli.py --replpython cli.py --role channel_explorer "discover high-quality public channels about local LLM fine-tuning and index their last 500 msgs"# all my dialogs, 1000 msgs each
python -m scripts.download_history --all --limit 1000
# just one channel, 5000 msgs
python -m scripts.download_history --dialog @somechannel --limit 5000Once indexed, the agent will naturally reach for idx_semantic_search for
fuzzy queries such as Chinese -> English matching and paraphrases.
Add to your MCP client config, for example ~/.cursor/mcp.json:
{
"mcpServers": {
"tg-agent": {
"command": "python",
"args": ["-m", "mcp_server.server"],
"cwd": "/absolute/path/to/Rewind.tg",
"env": { "PYTHONUNBUFFERED": "1" }
}
}
}For VS Code Copilot Chat, add the same under the
github.copilot.chat.mcpServers setting. Cursor / Copilot will then have
tg_search_global, tg_join_channel, idx_semantic_search,
tg_describe_media, spawn_subagent, and more.
user query
-> Orchestrator agent (ReAct loop, tool-calls)
-> spawn_subagent(role=...)
-> dialog_search
-> channel_explorer
-> link_crawler
-> shared tool belt
-> Telethon (MTProto, proxy)
-> Ollama (local LLM / vision / embeddings)
-> SQLite hybrid index (BM25 + cosine)
-> final answer
| Tool | Purpose |
|---|---|
tg_list_dialogs |
list user's chats / groups / channels / bots |
tg_search_global |
global search across all user's chats |
tg_search_in_dialog |
search inside one dialog |
tg_message_context |
expand around a hit |
tg_search_public_channels |
public directory search |
tg_join_channel |
join public / invite-only channels |
tg_resolve_link |
inspect a t.me/... link without joining |
tg_index_channel |
download channel history into local index |
idx_semantic_search |
BM25 + embedding hybrid search |
http_fetch |
fetch web URLs via proxy, cleaned HTML |
tg_describe_media |
download + describe media with the vision model |
spawn_subagent |
recursive delegation to a focused sub-agent |
All data stays on your machine (SQLite file + Telethon session). The agent performs no content filtering: your Telegram, your rules. Inbound prompt injection from message content is possible in theory, so do not run this against an account whose tool belt you would not trust to run locally.
Your api_hash is a secret, so keep it in .env (git-ignored). If it ever
leaks, rotate it at https://my.telegram.org. Never commit .env or data/
(session file + local index + downloaded media).