Skip to content

Conversation

@ethanndickson
Copy link
Member

Queued messages are now sent as soon as a tool completes execution, rather than waiting for the entire stream to finish.

Problem

Previously, queued messages were only sent on stream-end. In tool-using flows, this meant users had to wait for:

  1. Tool execution to complete
  2. LLM to process the tool result
  3. LLM to finish streaming its response

This created unnecessary latency when queueing messages during tool execution.

Solution

Extracted a shared sendQueuedMessages() method called from both:

  • tool-call-end: Sends queued messages immediately when tool completes
  • stream-end: Continues to handle non-tool streams

The first handler to fire clears the queue, so no duplicate sends occur. Non-tool streams continue to work exactly as before.

Changes

  • Added sendQueuedMessages() private method
  • Updated tool-call-end handler to auto-send
  • Refactored stream-end handler to use shared method

Net: +18 lines

Generated with mux

Extract sendQueuedMessages() method and call from both tool-call-end
and stream-end handlers. This sends queued messages as soon as a tool
completes execution rather than waiting for the full stream to finish,
reducing latency in tool-using flows.

Net: +18 lines (new method + updated handlers)
@ethanndickson ethanndickson added this pull request to the merge queue Nov 18, 2025
Merged via the queue into main with commit 5727930 Nov 18, 2025
13 checks passed
@ethanndickson ethanndickson deleted the queued-messages-tool-end-fix branch November 18, 2025 01:32
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