Skip to content

Commit 413d374

Browse files
authored
Merge pull request #2957 from loafoe/fix/tool-calls-filtering
fix(channels): prevent tool_calls from being dropped during streaming
2 parents d153952 + 89e7a61 commit 413d374

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

pkg/channels/manager.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ func outboundMessageIsToolFeedback(msg bus.OutboundMessage) bool {
169169
return strings.EqualFold(strings.TrimSpace(msg.Context.Raw["message_kind"]), "tool_feedback")
170170
}
171171

172+
func outboundMessageIsToolCalls(msg bus.OutboundMessage) bool {
173+
if len(msg.Context.Raw) == 0 {
174+
return false
175+
}
176+
return strings.EqualFold(strings.TrimSpace(msg.Context.Raw["message_kind"]), "tool_calls")
177+
}
178+
172179
func outboundMessageHasAuxiliaryKind(msg bus.OutboundMessage) bool {
173180
if len(msg.Context.Raw) == 0 {
174181
return false
@@ -379,6 +386,7 @@ func (m *Manager) preSend(ctx context.Context, name string, msg bus.OutboundMess
379386
}
380387

381388
isToolFeedback := outboundMessageIsToolFeedback(msg)
389+
isToolCalls := outboundMessageIsToolCalls(msg)
382390
isAuxiliaryMessage := outboundMessageHasAuxiliaryKind(msg)
383391
isFinalMessage := outboundMessageIsFinal(msg)
384392
separateToolFeedbackMessages := m.toolFeedbackSeparateMessagesEnabled()
@@ -388,7 +396,9 @@ func (m *Manager) preSend(ctx context.Context, name string, msg bus.OutboundMess
388396
// finalization bypasses the worker queue, so older queued feedback/thoughts
389397
// can arrive before the normal final outbound message that cleans up the
390398
// marker and placeholder.
391-
if isAuxiliaryMessage {
399+
// Note: tool_calls messages must NOT be dropped as they represent new tool
400+
// invocations for the current turn that must be delivered to the UI.
401+
if isAuxiliaryMessage && !isToolCalls {
392402
if _, loaded := m.streamActive.Load(streamKey); loaded {
393403
return nil, true
394404
}

0 commit comments

Comments
 (0)