Repository navigation
Preview Pi responses with Telegram message drafts - #18
Merged
Merged
Conversation
There was a problem hiding this comment.
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
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

$## 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.