Telegram Workflow
Draft + Edit two-step workflow on Telegram
Code
from agno.agent import Agent
from agno.db.sqlite import SqliteDb
from agno.models.openai import OpenAIChat
from agno.os.app import AgentOS
from agno.os.interfaces.telegram import Telegram
from agno.workflow.step import Step
from agno.workflow.steps import Steps
from agno.workflow.workflow import Workflow
agent_db = SqliteDb(
session_table="telegram_workflow_sessions", db_file="tmp/telegram_workflow.db"
)
drafter = Agent(
name="Drafter",
model=OpenAIChat(id="gpt-4o-mini"),
instructions="Draft a response to the user's message. Be helpful and informative.",
)
editor = Agent(
name="Editor",
model=OpenAIChat(id="gpt-4o-mini"),
instructions=[
"Review and polish the draft for clarity and conciseness.",
"Keep it short and suitable for a Telegram message.",
],
)
draft_step = Step(
name="draft",
agent=drafter,
description="Draft an initial response",
)
edit_step = Step(
name="edit",
agent=editor,
description="Edit and polish the draft",
)
telegram_workflow = Workflow(
name="Telegram Draft-Edit Workflow",
description="A two-step workflow that drafts and then edits responses for Telegram",
steps=[
Steps(
name="draft_and_edit",
description="Draft then edit a response",
steps=[draft_step, edit_step],
)
],
db=agent_db,
)
agent_os = AgentOS(
workflows=[telegram_workflow],
interfaces=[
Telegram(
workflow=telegram_workflow,
reply_to_mentions_only=True,
)
],
)
app = agent_os.get_app()
if __name__ == "__main__":
agent_os.serve(app="workflow:app", reload=True)Usage
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateSet Environment Variables
Use this secret as secret_token when registering the public webhook in the setup guide. Keep the same value in the server and registration terminals. APP_ENV=development bypasses webhook authentication, so clear it for this public callback flow.
export TELEGRAM_TOKEN=your-bot-token-from-botfather
export OPENAI_API_KEY=your-openai-api-key
export TELEGRAM_WEBHOOK_SECRET_TOKEN=replace-with-a-long-random-secret
unset APP_ENVInstall dependencies
uv pip install -U "agno[os,telegram]" openaiRun Example
python workflow.pyThe bot needs a public webhook URL to receive messages. See Telegram setup.
Key Features
- Two-Step Pipeline: Drafter writes an initial response, Editor polishes it
- Workflow on Telegram: The
Workflow(not individual agents) is passed to the Telegram interface - Sequential Steps:
StepschainsStepobjects in order - Persistent Sessions: SQLite database for conversation history across restarts