mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-06 18:07:28 +08:00
centralize outbound response post-processing for dialog consistency
This commit is contained in:
@@ -202,20 +202,10 @@ func (al *AgentLoop) Run(ctx context.Context) error {
|
|||||||
trigger := al.getTrigger(msg)
|
trigger := al.getTrigger(msg)
|
||||||
suppressed := false
|
suppressed := false
|
||||||
if response != "" {
|
if response != "" {
|
||||||
if shouldDropNoReply(response) {
|
if outbound, ok := al.prepareOutbound(msg, response); ok {
|
||||||
suppressed = true
|
al.bus.PublishOutbound(outbound)
|
||||||
} else {
|
} else {
|
||||||
clean, replyToID := parseReplyTag(response, msg.Metadata["message_id"])
|
suppressed = true
|
||||||
if al.shouldSuppressOutbound(msg, clean) {
|
|
||||||
suppressed = true
|
|
||||||
} else {
|
|
||||||
al.bus.PublishOutbound(bus.OutboundMessage{
|
|
||||||
Channel: msg.Channel,
|
|
||||||
ChatID: msg.ChatID,
|
|
||||||
Content: clean,
|
|
||||||
ReplyToID: replyToID,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
al.audit.Record(trigger, msg.Channel, msg.SessionKey, suppressed, err)
|
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
|
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) {
|
func (al *AgentLoop) ProcessDirect(ctx context.Context, content, sessionKey string) (string, error) {
|
||||||
msg := bus.InboundMessage{
|
msg := bus.InboundMessage{
|
||||||
Channel: "cli",
|
Channel: "cli",
|
||||||
|
|||||||
Reference in New Issue
Block a user