TowerBot is an open source, AI-powered Telegram bot for Frontier Tower citizens. It answers questions, provides insights, and leverages persistent memory, semantic search, and a temporal knowledge graph to empower our Telegram Channel.
This project is licensed under the MIT License and is free for both commercial and non-commercial use.
- Telegram Integration: Commands (
/ask,/connect,/request) and direct messaging - AI Agents: Specialized agents with LangGraph, memory management, and tool calling
- Temporal Knowledge Graph: Community interaction tracking with Graphiti
- REST API: Query the knowledge graph via
/api/v1/graph/queryendpoint - Authentication: API key authentication for REST API access
- Persistent Memory: LangMem integration for conversation context
- Dynamic Ontology: Auto-generated enums and type mappings from schema definitions
- Python 3.12+ with uv dependency management
- FastAPI (API backend)
- python-telegram-bot (Telegram integration)
- LangChain/LangGraph/LangMem (AI agents and memory)
- Graphiti (temporal knowledge graph)
- PostgreSQL with pgvector (optional vector storage, falls back to in-memory)
- OpenAI/Azure OpenAI (LLM services)
- pytest (testing with 91 test cases)
- Python 3.12+
- Docker (optional, for PostgreSQL)
- ngrok (for webhook tunneling)
Install uv package manager:
curl -LsSf https://astral.sh/uv/install.sh | shgit clone <your-repo-url>
cd towerbot
uv sync# Start PostgreSQL with pgvector
docker run --name postgres-towerbot \
-e POSTGRES_PASSWORD=postgres \
-p 5436:5432 \
-d pgvector/pgvector:pg17
# Create database and enable vector extension
sleep 3
PGPASSWORD=postgres psql -h localhost -p 5436 -U postgres \
-c "CREATE DATABASE towerbot;"
PGPASSWORD=postgres psql -h localhost -p 5436 -U postgres -d towerbot \
-c "CREATE EXTENSION IF NOT EXISTS vector;"Create .env file:
# Telegram (get from @BotFather)
BOT_TOKEN=your-telegram-bot-token
# OpenAI
OPENAI_API_KEY=your-openai-key
MODEL=gpt-4
EMBEDDING_MODEL=text-embedding-3-small
# Database (optional - uses in-memory fallback if not provided)
POSTGRES_CONN_STRING=postgresql://postgres:postgres@localhost:5436/towerbot
# Webhook (get free domain from ngrok.com)
WEBHOOK_URL=https://your-domain.ngrok-free.app
# Optional: Observability
LANGSMITH_API_KEY=your-langsmith-key
LANGCHAIN_TRACING_V2=true# Terminal 1: Start ngrok tunnel
ngrok http --domain=your-domain.ngrok-free.app 8000
# Terminal 2: Start application
./startup.sh- Add bot to your Telegram group
- Promote bot to admin (required for receiving webhooks and processing messages)
- Test with
/ask what is this bot?
graph TD
TG[Telegram Group] -->|Commands| BOT[TowerBot]
PM[Private Messages] -->|Direct Chat| BOT
BOT --> API[FastAPI Backend]
API --> AI[AI Service<br/>LangGraph Agents]
API --> GRAPH[Graph Service<br/>Graphiti + PostgreSQL]
API --> AUTH[Auth Service<br/>API Key Validation]
API --> REST["/api/v1/graph/query<br/>REST Endpoint"]
Core Components:
- AI Service: Dynamic agent system with memory and tool integration
- Graph Service: Temporal knowledge graph with episode tracking
- Auth Service: Multi-tier authentication with group validation
- REST API: External graph query access with API key auth
/ask <question>— Get AI-powered answers with context/connect <interest>— Find community connections and relationships/request <item>— Create supply requests- Direct Messages — Full conversational AI with persistent memory
Query the knowledge graph programmatically:
curl -X POST "https://your-server.com/api/v1/graph/query" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{"query": "Find all connections related to AI projects"}'API Key Authentication — Required for REST API access
# Run tests
uv run pytest
# Run with hot reload
uv run uvicorn app.main:app --reload --port 8000
# Generate ontology enums
uv run python scripts/generate_enums.py
# Run specific test categories
uv run pytest -m unit
uv run pytest -m integrationapp/
├── core/ # Configuration, constants, lifecycle
├── services/ # AI, graph, and auth services
├── schemas/ # Data models and ontology
├── api/ # FastAPI routes
├── main.py # Application entry point
└── webhook.py # Telegram webhook setup
tests/ # 91 comprehensive test cases
scripts/ # Enum generation utilities
static/ # Images and data files
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass:
uv run pytest - Submit a pull request
- FastAPI Documentation
- LangChain / LangGraph
- Graphiti (Temporal Knowledge Graph)
- python-telegram-bot
- pgvector (PostgreSQL Vector Extension)
This project is licensed under the MIT License.
