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