From a5f59ea6a5ad606659b20ae35e105a6c96b28d2a Mon Sep 17 00:00:00 2001 From: Acbox Date: Sat, 4 Apr 2026 17:17:35 +0800 Subject: [PATCH] fix(channel): strip agent tags from content parts in outbound messages StripAgentTags was only applied to the merged content string but not to individual ContentParts. On channels that don't support RichText (e.g. Telegram), buildChannelMessage joins part texts directly, causing raw // blocks to appear in the final message. --- internal/conversation/flow/assistant_output.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/internal/conversation/flow/assistant_output.go b/internal/conversation/flow/assistant_output.go index 942ef675..b0327e2d 100644 --- a/internal/conversation/flow/assistant_output.go +++ b/internal/conversation/flow/assistant_output.go @@ -30,6 +30,7 @@ func ExtractAssistantOutputs(messages []conversation.ModelMessage) []conversatio continue } content = agent.StripAgentTags(content) + parts = stripAgentTagsFromParts(parts) outputs = append(outputs, conversation.AssistantOutput{Content: content, Parts: parts}) } return outputs @@ -87,6 +88,22 @@ func visibleContentText(parts []conversation.ContentPart) string { return strings.TrimSpace(strings.Join(texts, "\n")) } +func stripAgentTagsFromParts(parts []conversation.ContentPart) []conversation.ContentPart { + if len(parts) == 0 { + return nil + } + result := make([]conversation.ContentPart, 0, len(parts)) + for _, p := range parts { + if strings.TrimSpace(p.Text) != "" { + p.Text = agent.StripAgentTags(p.Text) + } + if p.HasValue() { + result = append(result, p) + } + } + return result +} + func visibleContentPartText(part conversation.ContentPart) string { if strings.TrimSpace(part.Text) != "" { return part.Text