From e30ced52a3582d9667c43803510498a07287ed47 Mon Sep 17 00:00:00 2001 From: DBT Date: Mon, 23 Feb 2026 16:33:10 +0000 Subject: [PATCH] align dialog behavior with reply-tag stripping and NO_REPLY suppression --- pkg/agent/loop.go | 52 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 9b82703..1d0671b 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -203,14 +203,19 @@ func (al *AgentLoop) Run(ctx context.Context) error { trigger := al.getTrigger(msg) suppressed := false if response != "" { - if al.shouldSuppressOutbound(msg, response) { + if shouldDropNoReply(response) { suppressed = true } else { - al.bus.PublishOutbound(bus.OutboundMessage{ - Channel: msg.Channel, - ChatID: msg.ChatID, - Content: response, - }) + clean := stripReplyTags(response) + if al.shouldSuppressOutbound(msg, clean) { + suppressed = true + } else { + al.bus.PublishOutbound(bus.OutboundMessage{ + Channel: msg.Channel, + ChatID: msg.ChatID, + Content: clean, + }) + } } } al.audit.Record(trigger, msg.Channel, msg.SessionKey, suppressed, err) @@ -559,6 +564,8 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe "chat_id": msg.ChatID, }) + msg.Content = rewriteSystemMessageContent(msg.Content) + // Parse origin from chat_id (format: "channel:chat_id") var originChannel, originChatID string if idx := strings.Index(msg.ChatID, ":"); idx > 0 { @@ -919,6 +926,39 @@ func extractFirstSourceLine(text string) string { return "" } +func shouldDropNoReply(text string) bool { + t := strings.TrimSpace(text) + return strings.EqualFold(t, "NO_REPLY") +} + +func stripReplyTags(text string) string { + t := strings.TrimSpace(text) + if !strings.HasPrefix(t, "[[") { + return text + } + end := strings.Index(t, "]]") + if end <= 0 { + return text + } + tag := strings.ToLower(strings.TrimSpace(t[2:end])) + if strings.HasPrefix(tag, "reply_to_current") || strings.HasPrefix(tag, "reply_to:") || strings.HasPrefix(tag, "reply_to") { + return strings.TrimSpace(t[end+2:]) + } + return text +} + +func rewriteSystemMessageContent(content string) string { + c := strings.TrimSpace(content) + if !strings.HasPrefix(c, "[System Message]") { + return content + } + body := strings.TrimSpace(strings.TrimPrefix(c, "[System Message]")) + if body == "" { + return "Please summarize the system event in concise user-facing language." + } + return "Rewrite the following internal system update in concise user-facing language:\n\n" + body +} + func alSessionListForTool(sm *session.SessionManager, limit int) []tools.SessionInfo { items := sm.List(limit) out := make([]tools.SessionInfo, 0, len(items))