Skip to content

Preview Pi responses with Telegram message drafts - #18

Merged
alejandro-ao merged 3 commits into
mainfrom
feat/telegram-draft-streaming
Oct 1, 2026
Merged

alejandro-ao merged 3 commits into
mainfrom
feat/telegram-draft-streaming

Conversation

@alejandro-ao

Copy link
Copy Markdown
Owner

$## Summary\n- Stream Pi text deltas as throttled, ephemeral Telegram drafts in private chats; never expose thinking deltas.\n- Keep the full persistent answer gated on agent_settled; reset drafts across Pi retries and fall back to the working message for group chats or unsupported draft APIs.\n- Add tests for retry clearing, draft failures, preview limits, old SDK fallback, and final reply handling.\n\n## Verification\n- Python 3.11/3.14: ruff, mypy, pytest, uv build.\n- compileall and git diff --check.\n- Live Telegram test still needed before merging.

@alejandro-ao
alejandro-ao marked this pull request as ready for review October 1, 2026 10:28
Copilot AI balanced review requested due to automatic review settings October 1, 2026 10:28
@alejandro-ao
alejandro-ao merged commit 290ca1b into main Oct 1, 2026
3 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The asynchronous external Telegram API integration still requires the live validation identified in the PR description.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Adds private-chat Telegram draft previews while preserving agent_settled as the authoritative completion boundary.

Changes:

  • Streams throttled text and sanitized tool activity into ephemeral drafts.
  • Adds fallback handling and callback propagation through Pi RPC.
  • Documents and tests retry, failure, limit, and routing behavior.
File Description
pi_gateway/​telegram_bot.py Implements draft previews and routing.
pi_gateway/​pi_rpc.py Extracts safe streaming events.
pi_gateway/​session_manager.py Propagates preview callbacks.
tests/​test_telegram_drafts.py Tests draft behavior and fallback.
tests/​test_pi_rpc_settled.py Tests streaming and retry semantics.
README.md Documents user-facing preview behavior.
docs/​03-telegram-gateway.md Documents Telegram draft handling.
docs/​04-pi-rpc-integration.md Documents RPC preview events.
AGENTS.md Records implementation constraints.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

- Once Pi returns, it deletes the temporary message if possible.
- It sends the final assistant text split into chunks.
- In private chats with `sendMessageDraft` support (python-telegram-bot 22.7+), it coalesces Pi text deltas into drafts at most every 0.8 seconds, using a nonzero per-reply draft ID. The first successful draft removes the working message. The preview shows sanitized tool names during `tool_execution_start`/`tool_execution_end` (no arguments, output, or thinking text); concurrent tools show the most recently started active tool. The tool indicator disappears on completion, and retries clear it. Only the first 4,096 characters are previewed, with space reserved for the tool indicator; the preview is ephemeral (about 30 seconds) and may be replaced by retries. Errors disable drafts for that reply without interrupting Pi.
- Group chats, older SDKs, and replies without text deltas use the original working message. When Pi settles (or fails), the working message is removed if still present.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants