A persistent, autonomous AI companion that runs 24/7 on Railway. Maintains memory across conversations, reachable via Telegram, with its own "thinking time" via an autonomy loop.
Single async Python process running three things cooperatively:
- Starlette/Uvicorn — HTTP server receiving Telegram webhook POSTs
- python-telegram-bot Application — processes updates, routes to handlers
- JobQueue (APScheduler) — runs the autonomy loop on a configurable interval
- Message @BotFather on Telegram
- Send
/newbotand follow the prompts - Save the bot token
- Message @userinfobot on Telegram
- Save the numeric ID it returns
- Go to console.anthropic.com → API Keys
- Create a new key and save it
- Connect this repo to Railway
- Add a persistent volume mounted at
/data - Set environment variables (see
.env.example):TELEGRAM_BOT_TOKEN— from BotFatherANTHROPIC_API_KEY— from Anthropic consoleWEBHOOK_URL— your Railway app URL (e.g.https://your-app.railway.app)ALLOWED_USER_IDS— your Telegram user ID
- Deploy
# Copy and fill in environment variables
cp .env.example .env
source .env && export $(cut -d= -f1 .env)
# Install dependencies
pip install -r requirements.txt
# Run in polling mode (no webhook needed)
python main.py --polling/start— Welcome message/memory— View current memory state/forget— Clear current session
Five persistent memory files in /data/memory/:
| File | Purpose |
|---|---|
identity.md |
Personality and values (seeded once) |
user_context.md |
Accumulated facts about the user |
conversation_summary.md |
Rolling 7-day conversation summaries |
active_threads.md |
Ongoing projects and topics |
queue.md |
Follow-ups, reminders, ideas |
Memory synthesis runs automatically when:
- A session times out (30 min of inactivity)
- Message threshold is reached (10 messages in a session)
Runs every 60 minutes (configurable). Two-phase process:
- Think (Haiku, cheap) — review context, decide if action needed
- Act (Sonnet, quality) — compose message if warranted
Triple-gated proactive messaging:
- Quiet hours (23:00–08:00 UTC)
- Cooldown (2h between proactive messages)
- Daily limit (3 messages/day)
Can also journal and update the queue without messaging.
~$4-5/month at moderate use (10 messages/day, hourly autonomy):
- Conversations: ~$2-3 (Sonnet with prompt caching)
- Memory synthesis: ~$0.27 (Haiku, 30 sessions/month)
- Autonomy loop: ~$1.08 (Haiku, 720 cycles/month)
- Proactive messages: ~$0.36 (Sonnet, ~30 messages/month)
- Check
/healthreturns 200 - Message the bot — should respond with memory context loaded
- Send several messages, wait 30 min, message again — should reference earlier conversation
- Check logs for autonomy cycle entries every hour
- Run
/memoryto inspect current memory state - Check
/data/workspace/journal/for journal entries