Skip to content

feat(chat): enhance message streaming logic for tool responses#89

Open
Gourav-InfoTech wants to merge 1 commit intoYourGPT:betafrom
Gourav-InfoTech:fix/postToolText
Open

feat(chat): enhance message streaming logic for tool responses#89
Gourav-InfoTech wants to merge 1 commit intoYourGPT:betafrom
Gourav-InfoTech:fix/postToolText

Conversation

@Gourav-InfoTech
Copy link
Copy Markdown
Contributor

Description

Fixes a bug where post-tool text responses (e.g. after websearch/webanswer builtin tools) would either appear all-at-once instead of streaming live, or appear as duplicate messages when both the streaming path and the done handler inserted the same content.

Changes

  • Detect message:delta chunks that arrive with no active streamState (server-side tools like websearch that skip message:start) and auto-initialize a new assistant message so post-tool text streams live
  • Introduce postToolTextStreamed flag to signal that post-tool text was already delivered via the live-streaming path, preventing the done handler from inserting a duplicate
  • Introduce seenToolResult tracking in the done.messages loop to correctly distinguish pre-tool assistant text (skip — already streamed) from post-tool assistant text (insert only if not already streamed)
  • Refactor if/continue chain into a proper if/else if/else block for clarity

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)

Testing

  • I've tested this locally
  • I've added/updated tests
  • All existing tests pass

Checklist

  • My code follows the project's style guidelines
  • I've updated the documentation (if needed)
  • I've added tests that prove my fix/feature works
  • New and existing tests pass locally

- Introduced a mechanism to handle post-tool text streaming when a message:delta is received without a preceding message:start, allowing for live updates.
- Added a guard to prevent duplicate insertion of assistant messages that follow tool results, ensuring proper message flow.
- Improved debug logging for better traceability of streaming state changes.

This update refines the chat experience by ensuring that tool responses are integrated seamlessly into the conversation flow.
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 2026

@Gourav-InfoTech is attempting to deploy a commit to the Delta4 Infotech Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant