> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Bot vs Gateway

> Choose the right deployment model for your AI agents

Two ways to deploy AI agents for real-time communication: **Bot** for messaging platforms, **Gateway** for custom applications.

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TB
    subgraph "Bot Mode"
        U1[👤 User] -->|Message| P[📱 Platform]
        P -->|Webhook| B[🤖 Bot]
        B -->|Response| P
        P -->|Reply| U1
    end
    
    subgraph "Gateway Mode"
        U2[👤 User] -->|WebSocket| G[🗼 Gateway]
        G -->|Route| A1[🤖 Agent 1]
        G -->|Route| A2[🤖 Agent 2]
        A1 -->|Response| G
        G -->|Deliver| U2
    end
    
    classDef user fill:#8B0000,color:#fff
    classDef platform fill:#189AB4,color:#fff
    classDef bot fill:#8B0000,color:#fff
    classDef gateway fill:#F59E0B,color:#fff
    classDef agent fill:#8B0000,color:#fff
    
    class U1,U2 user
    class P platform
    class B bot
    class G gateway
    class A1,A2 agent
```

***

## Quick Comparison

| Feature       | Bot                        | Gateway                   |
| ------------- | -------------------------- | ------------------------- |
| **Use Case**  | Messaging platforms        | Custom applications       |
| **Platforms** | Telegram, Discord, Slack   | Any WebSocket client      |
| **Users**     | Single-user conversations  | Multi-user, multi-agent   |
| **Protocol**  | Platform-specific          | WebSocket                 |
| **CLI**       | `praisonai bot <platform>` | `praisonai serve gateway` |

***

## When to Use Bot

<CardGroup cols={2}>
  <Card title="Team Communication" icon="comments">
    Deploy to Slack/Discord for team assistants
  </Card>

  <Card title="Customer Support" icon="headset">
    Telegram bots for customer interactions
  </Card>

  <Card title="Personal Assistant" icon="user">
    Single-user conversational AI
  </Card>

  <Card title="Quick Deployment" icon="rocket">
    One command to production
  </Card>
</CardGroup>

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Deploy to Telegram in one command
praisonai bot telegram --token $TELEGRAM_BOT_TOKEN --memory --web
```

***

## When to Use Gateway

<CardGroup cols={2}>
  <Card title="Web Applications" icon="globe">
    Custom chat interfaces and dashboards
  </Card>

  <Card title="Multi-Agent Systems" icon="users">
    Coordinate multiple specialized agents
  </Card>

  <Card title="Real-time Dashboards" icon="chart-line">
    Live updates and streaming responses
  </Card>

  <Card title="Custom Protocols" icon="code">
    Full control over communication
  </Card>
</CardGroup>

```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
# Start gateway for custom applications
praisonai serve gateway --port 8765
```

***

## Architecture Deep Dive

<Tabs>
  <Tab title="Bot Architecture">
    ```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    sequenceDiagram
        participant User
        participant Platform as Telegram/Discord/Slack
        participant Bot as PraisonAI Bot
        participant Agent
        
        User->>Platform: Send message
        Platform->>Bot: Webhook/Polling
        Bot->>Agent: Process with tools
        Agent-->>Bot: Response
        Bot->>Platform: Send reply
        Platform-->>User: Display message
    ```

    **Key Points:**

    * Platform handles user authentication
    * Bot receives messages via webhook or polling
    * Multi-agent routing per bot (dm → agent A, group → agent B)
    * Platform-specific features (reactions, threads, etc.)
  </Tab>

  <Tab title="Gateway Architecture">
    ```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    sequenceDiagram
        participant Client as Web Client
        participant Gateway
        participant Session
        participant Agent1 as Agent 1
        participant Agent2 as Agent 2
        
        Client->>Gateway: Connect (WebSocket)
        Gateway->>Session: Create session
        Gateway-->>Client: Session ID
        Client->>Gateway: Join agent-1
        Gateway->>Agent1: Route message
        Agent1->>Agent2: Handoff (if needed)
        Agent2-->>Gateway: Response
        Gateway-->>Client: Deliver response
    ```

    **Key Points:**

    * Direct WebSocket connection
    * Multiple agents per gateway
    * Session-based state management
    * Agent-to-agent communication
  </Tab>
</Tabs>

***

## Feature Comparison

### Capabilities Support

| Capability     | Bot                            | Gateway                        |
| -------------- | ------------------------------ | ------------------------------ |
| Memory         | ✅ `--memory`                   | ✅ Session state                |
| Knowledge/RAG  | ✅ `--knowledge`                | ✅ Per-agent                    |
| Tools          | ✅ `--tools`                    | ✅ Per-agent                    |
| Web Search     | ✅ `--web`                      | ✅ Per-agent                    |
| Browser        | ✅ `--browser`                  | ✅ Per-agent                    |
| Thinking Mode  | ✅ `--thinking`                 | ✅ Per-agent                    |
| Multi-Agent    | ✅ Context-based routing        | ✅ Multiple agents with routing |
| Multi-Platform | ✅ All 4 platforms concurrently | ✅ WebSocket + bots             |
| Custom UI      | ❌ Platform UI                  | ✅ Full control                 |

### Deployment

| Aspect  | Bot                                              | Gateway                      |
| ------- | ------------------------------------------------ | ---------------------------- |
| Setup   | Platform token required                          | No external deps             |
| Scaling | Multiple bots per platform via `platform:` field | Multiple clients per gateway |
| Auth    | Platform handles                                 | You implement                |
| SSL     | Platform handles                                 | You configure                |

***

## Code Examples

<Tabs>
  <Tab title="Bot (Telegram)">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonai.bots import TelegramBot
    from praisonaiagents import Agent

    # Create agent with capabilities
    agent = Agent(
        name="assistant",
        instructions="You are a helpful assistant.",
        memory=True,
        knowledge=["./docs/"]
    )

    # Deploy to Telegram
    bot = TelegramBot(
        token="YOUR_BOT_TOKEN",
        agent=agent
    )

    # Start bot
    await bot.start()
    ```

    **CLI equivalent:**

    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    praisonai bot telegram --token $TOKEN --memory --knowledge
    ```
  </Tab>

  <Tab title="Gateway (WebSocket)">
    ```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    from praisonai.gateway import WebSocketGateway
    from praisonaiagents import Agent, GatewayConfig

    # Create gateway
    config = GatewayConfig(host="0.0.0.0", port=8765)
    gateway = WebSocketGateway(config=config)

    # Register multiple agents
    researcher = Agent(name="researcher", instructions="Research topics")
    writer = Agent(name="writer", instructions="Write content")

    gateway.register_agent(researcher)
    gateway.register_agent(writer)

    # Start gateway
    await gateway.start()
    ```

    **CLI equivalent:**

    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    praisonai serve gateway --port 8765 --agents agents.yaml
    ```
  </Tab>
</Tabs>

***

## Migration Guide

### Bot to Gateway

Moving from bot to gateway for more control:

<Steps>
  <Step title="Extract Agent Configuration">
    ```yaml theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    # agents.yaml
    agents:
      - name: assistant
        instructions: Your current bot instructions
        memory: true
        tools:
          - search_web
    ```
  </Step>

  <Step title="Start Gateway">
    ```bash theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    praisonai serve gateway --port 8765 --agents agents.yaml
    ```
  </Step>

  <Step title="Connect Your Client">
    ```javascript theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
    const ws = new WebSocket('ws://localhost:8765/ws');

    ws.onopen = () => {
      ws.send(JSON.stringify({
        type: 'join',
        agent_id: 'assistant'
      }));
    };

    ws.onmessage = (event) => {
      const data = JSON.parse(event.data);
      console.log('Response:', data.content);
    };
    ```
  </Step>
</Steps>

***

## Decision Tree

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
graph TD
    A[Need real-time AI?] -->|Yes| B{Platform?}
    B -->|Telegram/Discord/Slack| C[Use Bot]
    B -->|Custom App| D{Multi-agent?}
    D -->|Yes| E[Use Gateway]
    D -->|No| F{Need custom UI?}
    F -->|Yes| E
    F -->|No| G[Consider Bot or Gateway]
    
    classDef decision fill:#F59E0B,color:#fff
    classDef result fill:#8B0000,color:#fff
    
    class A,B,D,F decision
    class C,E,G result
```

***

## Related

<CardGroup cols={2}>
  <Card title="Bot CLI" icon="robot" href="/docs/cli/bot">
    Full bot CLI reference
  </Card>

  <Card title="Gateway Feature" icon="tower-broadcast" href="/docs/features/gateway">
    Gateway configuration guide
  </Card>

  <Card title="Multi-Agent" icon="users" href="/docs/features/multi-agent">
    Multi-agent coordination
  </Card>

  <Card title="Serve CLI" icon="server" href="/docs/cli/serve">
    All serve commands
  </Card>
</CardGroup>
