Multi-Agent Telegram Team
Researcher + Writer team coordinating on Telegram
Code
1from kern.agent import Agent2from kern.db.sqlite import SqliteDb3from kern.models.openai import OpenAIChat4from kern.os.app import AgentOS5from kern.os.interfaces.telegram import Telegram6from kern.team import Team78agent_db = SqliteDb(9 session_table="telegram_team_sessions", db_file="tmp/telegram_team.db"10)1112researcher = Agent(13 name="Researcher",14 model=OpenAIChat(id="gpt-4o-mini"),15 role="Researches topics and provides detailed factual information.",16 instructions=["Provide well-researched, factual information on the given topic."],17)1819writer = Agent(20 name="Writer",21 model=OpenAIChat(id="gpt-4o-mini"),22 role="Takes research and writes clear, engaging summaries.",23 instructions=["Write concise, engaging summaries based on the research provided."],24)2526telegram_team = Team(27 name="Telegram Research Team",28 model=OpenAIChat(id="gpt-4o-mini"),29 members=[researcher, writer],30 db=agent_db,31 instructions=[32 "You coordinate a research team on Telegram.",33 "Use the Researcher to gather facts, then the Writer to create a response.",34 "Keep responses concise for Telegram.",35 ],36 add_history_to_context=True,37 num_history_runs=3,38 add_datetime_to_context=True,39 markdown=True,40)4142agent_os = AgentOS(43 teams=[telegram_team],44 interfaces=[45 Telegram(46 team=telegram_team,47 reply_to_mentions_only=True,48 )49 ],50)51app = agent_os.get_app()5253if __name__ == "__main__":54 agent_os.serve(app="team:app", reload=True)Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateSet Environment Variables
1export TELEGRAM_TOKEN=your-bot-token-from-botfather2export OPENAI_API_KEY=your-openai-api-key3export APP_ENV=developmentInstall dependencies
1uv pip install -U "kern-ai[telegram]"Run Example
1python team.pyKey Features
- Multi-Agent Coordination: Team leader delegates to Researcher and Writer agents
- Specialized Roles: Each agent has a focused responsibility
- Team on Telegram: The
Teamis passed directly to the Telegram interface - Persistent Memory: SQLite database for session storage
- Group Chat Support: Only responds when mentioned in groups