From 21c6e7808cb0de403e77000d3f9a559f1c4414ca Mon Sep 17 00:00:00 2001 From: Huaaudio Date: Sat, 21 Mar 2026 18:31:15 +0100 Subject: [PATCH] fix tool_call tts --- pkg/agent/loop.go | 9 +++++++++ pkg/bus/types.go | 9 +++++---- pkg/channels/discord/discord.go | 9 ++++++++- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 54a2bfb96..4c44f2ea5 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -1379,6 +1379,9 @@ func (al *AgentLoop) runLLMIteration( Channel: opts.Channel, ChatID: opts.ChatID, Content: feedbackMsg, + Metadata: map[string]string{ + "is_tool_call": "true", + }, }) fbCancel() } @@ -1397,6 +1400,9 @@ func (al *AgentLoop) runLLMIteration( Channel: opts.Channel, ChatID: opts.ChatID, Content: result.ForUser, + Metadata: map[string]string{ + "is_tool_call": "true", + }, }) } @@ -1447,6 +1453,9 @@ func (al *AgentLoop) runLLMIteration( Channel: opts.Channel, ChatID: opts.ChatID, Content: r.result.ForUser, + Metadata: map[string]string{ + "is_tool_call": "true", + }, }) logger.DebugCF("agent", "Sent tool result to user", map[string]any{ diff --git a/pkg/bus/types.go b/pkg/bus/types.go index c648fb0ce..15aebc345 100644 --- a/pkg/bus/types.go +++ b/pkg/bus/types.go @@ -30,10 +30,11 @@ type InboundMessage struct { } type OutboundMessage struct { - Channel string `json:"channel"` - ChatID string `json:"chat_id"` - Content string `json:"content"` - ReplyToMessageID string `json:"reply_to_message_id,omitempty"` + Channel string `json:"channel"` + ChatID string `json:"chat_id"` + Content string `json:"content"` + ReplyToMessageID string `json:"reply_to_message_id,omitempty"` + Metadata map[string]string `json:"metadata,omitempty"` } // MediaPart describes a single media attachment to send. diff --git a/pkg/channels/discord/discord.go b/pkg/channels/discord/discord.go index 2c7407171..cff8b7a16 100644 --- a/pkg/channels/discord/discord.go +++ b/pkg/channels/discord/discord.go @@ -154,7 +154,14 @@ func (c *DiscordChannel) Send(ctx context.Context, msg bus.OutboundMessage) erro return nil } - if c.tts != nil { + isToolCall := false + if msg.Metadata != nil { + if val, ok := msg.Metadata["is_tool_call"]; ok && val == "true" { + isToolCall = true + } + } + + if c.tts != nil && !isToolCall { if ch, err := c.session.State.Channel(channelID); err == nil && ch.GuildID != "" { if vc, ok := c.session.VoiceConnections[ch.GuildID]; ok && vc != nil { // Cancel any previous TTS playback