Merge pull request #2957 from loafoe/fix/tool-calls-filtering
fix(channels): prevent tool_calls from being dropped during streaming
This commit is contained in:
commit
413d37494b
1 changed files with 11 additions and 1 deletions
|
|
@ -169,6 +169,13 @@ func outboundMessageIsToolFeedback(msg bus.OutboundMessage) bool {
|
||||||
return strings.EqualFold(strings.TrimSpace(msg.Context.Raw["message_kind"]), "tool_feedback")
|
return strings.EqualFold(strings.TrimSpace(msg.Context.Raw["message_kind"]), "tool_feedback")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func outboundMessageIsToolCalls(msg bus.OutboundMessage) bool {
|
||||||
|
if len(msg.Context.Raw) == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return strings.EqualFold(strings.TrimSpace(msg.Context.Raw["message_kind"]), "tool_calls")
|
||||||
|
}
|
||||||
|
|
||||||
func outboundMessageHasAuxiliaryKind(msg bus.OutboundMessage) bool {
|
func outboundMessageHasAuxiliaryKind(msg bus.OutboundMessage) bool {
|
||||||
if len(msg.Context.Raw) == 0 {
|
if len(msg.Context.Raw) == 0 {
|
||||||
return false
|
return false
|
||||||
|
|
@ -379,6 +386,7 @@ func (m *Manager) preSend(ctx context.Context, name string, msg bus.OutboundMess
|
||||||
}
|
}
|
||||||
|
|
||||||
isToolFeedback := outboundMessageIsToolFeedback(msg)
|
isToolFeedback := outboundMessageIsToolFeedback(msg)
|
||||||
|
isToolCalls := outboundMessageIsToolCalls(msg)
|
||||||
isAuxiliaryMessage := outboundMessageHasAuxiliaryKind(msg)
|
isAuxiliaryMessage := outboundMessageHasAuxiliaryKind(msg)
|
||||||
isFinalMessage := outboundMessageIsFinal(msg)
|
isFinalMessage := outboundMessageIsFinal(msg)
|
||||||
separateToolFeedbackMessages := m.toolFeedbackSeparateMessagesEnabled()
|
separateToolFeedbackMessages := m.toolFeedbackSeparateMessagesEnabled()
|
||||||
|
|
@ -388,7 +396,9 @@ func (m *Manager) preSend(ctx context.Context, name string, msg bus.OutboundMess
|
||||||
// finalization bypasses the worker queue, so older queued feedback/thoughts
|
// finalization bypasses the worker queue, so older queued feedback/thoughts
|
||||||
// can arrive before the normal final outbound message that cleans up the
|
// can arrive before the normal final outbound message that cleans up the
|
||||||
// marker and placeholder.
|
// marker and placeholder.
|
||||||
if isAuxiliaryMessage {
|
// Note: tool_calls messages must NOT be dropped as they represent new tool
|
||||||
|
// invocations for the current turn that must be delivered to the UI.
|
||||||
|
if isAuxiliaryMessage && !isToolCalls {
|
||||||
if _, loaded := m.streamActive.Load(streamKey); loaded {
|
if _, loaded := m.streamActive.Load(streamKey); loaded {
|
||||||
return nil, true
|
return nil, true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue