Skip to content

[Enhancement] Renew Telegram typing indicator during long agent.chat() calls #1748

@Dhivya-Bharathy

Description

@Dhivya-Bharathy

[Enhancement] Renew Telegram typing indicator during long agent.chat() calls

Labels: enhancement, gateway, telegram, ux


Overview

Telegram shows a "typing…" indicator when a bot calls send_action("typing"). That indicator expires after approximately 5 seconds. PraisonAI sends it once, immediately before calling agent.chat() — a blocking operation that routinely takes 20–30 seconds when the agent uses RAG search, tool calls, and LLM inference.

From the user's perspective, the bot goes completely silent for half a minute, then suddenly replies. Many operators assume the bot is broken and send duplicate messages or restart the gateway.

This was observed in a Hermes workforce deployment: @mervincfo_bot responded correctly but only after ~25 seconds with zero feedback after the initial typing bubble disappeared.


What the user sees

Telegram UX timeline (current behavior)

T+0s   User sends: "What is our Q1 burn rate?"
T+0s   Bot shows "typing…" (send_action once)
T+5s   "typing…" disappears (Telegram timeout)
T+5–25s  Nothing. User thinks bot is dead.
T+25s  Full CFO answer arrives.

User messages (typical)

  • "Bot isn't working"
  • "I sent three messages, no reply"
  • "Is the gateway down? Health says healthy."

Health endpoint reports "running": true. The bot is working — it just looks broken.


Architecture — message handling timeline

sequenceDiagram
    participant U as Telegram User
    participant G as Gateway polling handler
    participant A as Agent (RAG + tools + LLM)
    participant T as Telegram API

    U->>G: "What is our Q1 burn rate?"
    G->>T: send_action("typing")  ← only once
    T-->>U: "typing…" visible

    Note over G,A: agent.chat() — 20–30 seconds
    G->>A: search_knowledge + LLM call
    A-->>G: response text

    Note over T,U: typing indicator expired at T+5s
    G->>T: reply_text(response)
    T-->>U: Full answer at T+25s
Loading

Both code paths share this pattern:

  • Gateway: _start_telegram_bot_polling()handle_message() → one send_actionbot._session.chat()
  • Standalone: TelegramBot.handle_message() → one send_actionbot._session.chat()

There is no background task, no renewal loop, and no default acknowledgment emoji in gateway-generated configs.


Why agent.chat() takes so long (not a bug, but UX-critical)

In a typical workforce agent turn:

Step Duration
Embedding + vector search (search_knowledge) 2–5s
LLM call with tool result context 5–15s
Optional second LLM pass (reflection, formatting) 5–10s
Network latency 1–3s
Total 15–30s common

This is expected for RAG-enabled agents. The UX gap is not slow inference — it is zero feedback after second 5.


Telegram platform constraints

  • send_action("typing") must be re-sent periodically to keep the indicator visible.
  • Telegram Bot API docs and community practice: renew every 4–5 seconds during long operations.
  • send_action("upload_photo") or other actions can substitute but typing is the standard chat UX.
  • Reaction emoji (ack_emoji: "⏳") can provide immediate visual ack independent of typing — PraisonAI supports this via bot._ack but it is not enabled by default in onboard configs.

Proposed fix

1. Typing renewal task

async def _typing_loop(chat, interval=4.0):
    try:
        while True:
            await chat.send_action("typing")
            await asyncio.sleep(interval)
    except asyncio.CancelledError:
        pass
  • Start task before agent.chat().
  • Cancel in finally when response is sent or on error.
  • Apply in both gateway polling handler and native TelegramBot.handle_message().

2. Optional immediate ack

Enable ack_emoji: "⏳" (or configurable) in onboard-generated gateway configs so users get instant feedback even before typing renewal kicks in.

3. Shared helper

Single TypingIndicator utility in praisonai.bots to avoid duplicating renewal logic across gateway and standalone paths.


What this is NOT

  • Not a request to make agents faster (separate performance topic).
  • Not a duplicate of slow LLM latency issues.
  • No existing GitHub issue tracks typing renewal.

Acceptance criteria

  • Typing indicator remains visible for agent runs lasting 30+ seconds
  • Renewal task cancelled cleanly on success, error, or new message from same user
  • No runaway tasks if user sends rapid-fire messages
  • Works in both gateway polling and standalone bot modes
  • Document expected response latency in onboard Done panel ("Replies may take up to 30s")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentationperformance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions