From 9b4fef02bb503b81454d98e5da22d400bb2e325c Mon Sep 17 00:00:00 2001 From: DBT Date: Mon, 23 Feb 2026 17:26:34 +0000 Subject: [PATCH] centralize outbound response post-processing for dialog consistency --- pkg/agent/loop.go | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index e648fed..49b7c12 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -202,20 +202,10 @@ func (al *AgentLoop) Run(ctx context.Context) error { trigger := al.getTrigger(msg) suppressed := false if response != "" { - if shouldDropNoReply(response) { - suppressed = true + if outbound, ok := al.prepareOutbound(msg, response); ok { + al.bus.PublishOutbound(outbound) } else { - clean, replyToID := parseReplyTag(response, msg.Metadata["message_id"]) - if al.shouldSuppressOutbound(msg, clean) { - suppressed = true - } else { - al.bus.PublishOutbound(bus.OutboundMessage{ - Channel: msg.Channel, - ChatID: msg.ChatID, - Content: clean, - ReplyToID: replyToID, - }) - } + suppressed = true } } al.audit.Record(trigger, msg.Channel, msg.SessionKey, suppressed, err) @@ -269,6 +259,30 @@ func (al *AgentLoop) shouldSuppressOutbound(msg bus.InboundMessage, response str return len(r) <= maxChars } +func (al *AgentLoop) prepareOutbound(msg bus.InboundMessage, response string) (bus.OutboundMessage, bool) { + if shouldDropNoReply(response) { + return bus.OutboundMessage{}, false + } + currentMsgID := "" + if msg.Metadata != nil { + currentMsgID = msg.Metadata["message_id"] + } + clean, replyToID := parseReplyTag(response, currentMsgID) + clean = strings.TrimSpace(clean) + if clean == "" { + return bus.OutboundMessage{}, false + } + if al.shouldSuppressOutbound(msg, clean) { + return bus.OutboundMessage{}, false + } + return bus.OutboundMessage{ + Channel: msg.Channel, + ChatID: msg.ChatID, + Content: clean, + ReplyToID: strings.TrimSpace(replyToID), + }, true +} + func (al *AgentLoop) ProcessDirect(ctx context.Context, content, sessionKey string) (string, error) { msg := bus.InboundMessage{ Channel: "cli",