-
Notifications
You must be signed in to change notification settings - Fork 303
[DNM] Only send the delta on the partial tool call #2105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package app | ||
|
|
||
| import ( | ||
| "cmp" | ||
| "context" | ||
| "encoding/base64" | ||
| "errors" | ||
|
|
@@ -997,12 +998,24 @@ func (a *App) mergeEvents(events []tea.Msg) []tea.Msg { | |
| result = append(result, merged) | ||
|
|
||
| case *runtime.PartialToolCallEvent: | ||
| // For PartialToolCallEvent, keep only the latest one per tool call ID | ||
| // Only merge consecutive events with the same ID | ||
| // For PartialToolCallEvent, merge consecutive events with the same tool call ID | ||
| // by concatenating argument deltas | ||
| latest := ev | ||
| for i+1 < len(events) { | ||
| if next, ok := events[i+1].(*runtime.PartialToolCallEvent); ok && next.ToolCall.ID == ev.ToolCall.ID { | ||
| latest = next | ||
| latest = &runtime.PartialToolCallEvent{ | ||
| Type: ev.Type, | ||
| ToolCall: tools.ToolCall{ | ||
| ID: ev.ToolCall.ID, | ||
| Type: ev.ToolCall.Type, | ||
| Function: tools.FunctionCall{ | ||
| Name: cmp.Or(next.ToolCall.Function.Name, latest.ToolCall.Function.Name), | ||
| Arguments: latest.ToolCall.Function.Arguments + next.ToolCall.Function.Arguments, | ||
| }, | ||
| }, | ||
| ToolDefinition: next.ToolDefinition, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 MEDIUM: Inconsistent AgentContext and ToolDefinition sources in merged event The merged event uses The Issue: AgentContext: ev.AgentContext, // from first event
ToolDefinition: next.ToolDefinition, // from last eventThis means the timestamp/context metadata comes from when the tool call was initiated, but the tool definition comes from the last delta event. While tool definitions are unlikely to change mid-stream, this violates consistency and could cause subtle bugs if tool definitions are updated dynamically. Recommendation: ToolDefinition: ev.ToolDefinition, |
||
| AgentContext: ev.AgentContext, | ||
| } | ||
| i++ | ||
| } else { | ||
| break | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 HIGH: Function name lost during consecutive PartialToolCallEvent merges
The
cmp.Or(next.ToolCall.Function.Name, latest.ToolCall.Function.Name)logic is incorrect for merging delta events.The Problem:
evcontains the full function name (accumulated from streaming.go)nexthave empty names because they're just argument deltascmp.Orreturns the first non-empty value, preferringnext.ToolCall.Function.Name(empty) overlatest.ToolCall.Function.NameThe Fix:
Use
ev.ToolCall.Function.Name(from the first event in the merge chain) instead:This preserves the name learned from the first event throughout all subsequent merges.