feat: implement streaming reply modes for channel bots#1922
Conversation
- Add DraftStreamer helper class for live draft updates with rate limiting - Integrate streaming into BotSessionManager with stream_callback support - Add StreamingConfigSchema with validation for mode, intervals, and deltas - Update Telegram bot with full streaming support and proper control flow - Support draft mode (progressive content) and progress mode (tool status) - Maintain backward compatibility with existing non-streaming behavior Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com>
|
@coderabbitai review |
|
/review |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
✅ Action performedReview finished.
|
|
Warning Review limit reached
More reviews will be available in 3 minutes and 16 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more credits in the billing tab to continue. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@copilot Do a thorough review of this PR. Read ALL existing reviewer comments above from Qodo, Coderabbit, and Gemini first — incorporate their findings. Review areas:
|
Greptile SummaryThis PR adds live-draft streaming reply support for Telegram channel bots, connecting SDK streaming events to progressive message edits via a new
Confidence Score: 3/5Two defects on the new streaming code path need to be resolved before this is production-ready. The streaming finalization calls
Important Files Changed
Sequence DiagramsequenceDiagram
participant User as Telegram User
participant TBot as TelegramBot
participant Sess as BotSessionManager
participant Agent as Agent.astart()
participant DS as DraftStreamer
participant TG as Telegram API
User->>TBot: message
TBot->>DS: start() → send placeholder
DS->>TG: send_message("🤔 Thinking...")
TG-->>DS: message_id
TBot->>Sess: "chat(..., stream_callback=streamer.on_event)"
Sess->>Agent: astart(prompt, stream_callback)
loop token/tool events
Agent-->>DS: on_event(DELTA_TEXT / TOOL_CALL_START)
DS->>DS: _schedule_update() → asyncio.create_task
DS->>TG: edit_message_text(partial content)
end
Agent-->>Sess: final response
Sess-->>TBot: response string
TBot->>TBot: fire_message_sending(response)
TBot->>DS: finalize(hooked_content)
DS->>TG: edit_message_text(final content) ⚠️ no length check
TBot->>TBot: fire_message_sent(hooked_content)
Reviews (2): Last reviewed commit: "fix: resolve P1 critical issues in strea..." | Re-trigger Greptile |
|
@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Focus ONLY on Python packages (praisonaiagents, praisonai). Do NOT modify praisonai-rust or praisonai-ts. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding. Phase 1: Review per AGENTS.md
Phase 2: FIX Valid Issues Phase 3: Final Verdict |
|
Claude finished @MervinPraison's task —— View job ✅ Final Architecture Review CompletePhase 1: Review per AGENTS.md ✅
Phase 2: Fix Valid Issues ✅
Phase 3: Final Verdict ✅
🎯 APPROVED FOR MERGESummary of Changes Made:
Architecture Assessment:✅ Protocol-Driven: BotAdapter protocol correctly placed in core, implementations in wrapper The PR now meets all PraisonAI architecture guidelines and resolves the critical issues identified by previous reviewers. |
- Fix message hooks bypass: Add fire_message_sending/fire_message_sent to streaming path - Fix blocking asyncio.sleep: Replace inline sleep with background task scheduling - Fix AutonomyResult handling: Extract output field when autonomy enabled - Fix dead code: Properly assign _update_task for cancellation logic Resolves critical issues identified in Greptile review for streaming functionality. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
| # Finalize with complete response (after hook processing) | ||
| await streamer.finalize(send_result["content"]) |
There was a problem hiding this comment.
Streaming finalization bypasses long-message chunking and media extraction
streamer.finalize(send_result["content"]) edits the placeholder in-place via edit_message_text, which has a 4 096-character hard limit. Any response longer than that causes a BadRequest exception that finalize() silently swallows (logged only as a warning), leaving the user with whatever partial content was last successfully edited in — the complete final response is dropped.
The non-streaming path routes through _send_response_with_media → _send_long_message, which chunks long text and also extracts MEDIA: tags to deliver audio/file attachments. The streaming path skips both. A simple fix is to fall back to _send_response_with_media (as a new message) when finalize() fails, or to truncate inside finalize() for in-place edits and send overflow as follow-up messages.
Fixes #1916
Summary
Implements live draft/streaming reply functionality for channel bots, connecting core SDK streaming events to bot channel message edits for progressive response delivery.
Key Features
Implementation Details
Testing
Generated with Claude Code