Conversation
Owner
Author
|
Идея |
Owner
Author
|
Fixed. Tool call events are now sent to Also did a round of refactoring to keep the growing
Added a test for interleaved token and tool call event ordering ( |
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
This PR fixes tool call assembly from streaming chunks in
Session.Previously, providers that stream tool calls in multiple partial events (first chunk contains
CallID, subsequent chunks contain only argument fragments) causedEventNewToolCallevents to be forwarded individually — resulting in broken, incomplete argument JSON being delivered to the caller.Now,
Sessionaccumulates partial tool call chunks and assembles them into complete events before sending them downstream.Changes
1. Partial tool call assembly in
SessionThis ensures:
CallID) initializes a new tool call entry.CallID) are appended to the last open tool call'sContent.EventNewToolCallis sent only afterEventCompletionEnded.2. Removed redundant event modification logic
The
modifiedEventpattern was replaced with a unifiedsend()helper andskipEventflag.3. Added
send()helperEliminates duplicated
selectblocks and handles context cancellation uniformly.Tests
chat
New tests added in
chat/chat_test.go:Context cancellation:
TestComplete_ContextCancelledDuringStream— cancellation while streaming tokensTestSession_ContextCancelledDuringTokenCollection— cancellation before completion arrivesTestSession_ContextCancelledWhileWaitingForApproval— cancellation before user resolves a tool callTestSession_ContextCancelledBetweenRounds— cancellation between completion roundsTool call assembly:
TestSession_ToolCallAssembly_Basic— single tool call assembled from 3 chunksTestSession_ToolCallAssembly_MultipleToolsWithAssembly— 3 tool calls (2 assembled, 1 complete) in one completionTestSession_ToolCallAssembly_LargeContent— 20+ chunk assembly into a single tool callCloses #19