> ## Documentation Index
> Fetch the complete documentation index at: https://agno-v2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Multiple Instances

> Multiple Telegram bots on a single AgentOS server

## Code

```python multiple_instances.py theme={null}
import os

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.tools.websearch import WebSearchTools

agent_db = SqliteDb(db_file="tmp/persistent_memory.db")

basic_agent = Agent(
    name="Basic Agent",
    model=OpenAIChat(id="gpt-5.2"),
    db=agent_db,
    add_history_to_context=True,
    num_history_runs=3,
    add_datetime_to_context=True,
    markdown=True,
)

web_research_agent = Agent(
    name="Web Research Agent",
    model=OpenAIChat(id="gpt-5.2"),
    db=agent_db,
    tools=[WebSearchTools()],
    add_history_to_context=True,
    num_history_runs=3,
    add_datetime_to_context=True,
)

# Telegram only supports one webhook per bot token, so each interface needs its own bot.
# Create two bots via @BotFather and pass each token explicitly.
agent_os = AgentOS(
    agents=[basic_agent, web_research_agent],
    interfaces=[
        Telegram(agent=basic_agent, prefix="/basic", token=os.getenv("TELEGRAM_TOKEN_BASIC")),
        Telegram(agent=web_research_agent, prefix="/web-research", token=os.getenv("TELEGRAM_TOKEN_RESEARCH")),
    ],
)
app = agent_os.get_app()

if __name__ == "__main__":
    agent_os.serve(app="multiple_instances:app", reload=True)
```

## Usage

<Snippet file="create-venv-step.mdx" />

**1. Set Environment Variables**

```bash theme={null}
export TELEGRAM_TOKEN_BASIC=bot-token-for-basic-agent
export TELEGRAM_TOKEN_RESEARCH=bot-token-for-research-agent
export OPENAI_API_KEY=your-openai-api-key
export APP_ENV=development
```

**2. Install dependencies**

```bash theme={null}
uv pip install -U "agno[os,telegram]" openai ddgs
```

**3. Run Example**

```bash theme={null}
python multiple_instances.py
```

**4. Start a Public Tunnel**

In a separate terminal, start ngrok for the AgentOS port:

```bash theme={null}
ngrok http 7777
```

Copy the HTTPS forwarding URL, then export it in the terminal where you will register the webhooks:

```bash theme={null}
export NGROK_URL=https://your-subdomain.ngrok-free.app
```

**5. Register Webhooks**

Register a webhook for each bot token:

```bash theme={null}
curl "https://api.telegram.org/bot${TELEGRAM_TOKEN_BASIC}/setWebhook?url=${NGROK_URL}/basic/webhook"
curl "https://api.telegram.org/bot${TELEGRAM_TOKEN_RESEARCH}/setWebhook?url=${NGROK_URL}/web-research/webhook"
```

See [Telegram setup](https://agno-v2.mintlify.site/agent-os/interfaces/telegram/setup.md) for BotFather and production webhook-secret configuration.

## Key Features

* **Prefix-Based Routing**: Each agent gets its own webhook path (`/basic/webhook`, `/web-research/webhook`)
* **Shared Server**: Both agents run on a single AgentOS instance
* **Separate Bot Tokens**: Each interface uses its own BotFather bot (Telegram allows only one webhook per token)
* **Shared Database**: Both agents share the same SQLite database


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.