mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-20 07:17:29 +08:00
align dialog behavior with reply-tag stripping and NO_REPLY suppression
This commit is contained in:
@@ -203,14 +203,19 @@ 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 al.shouldSuppressOutbound(msg, response) {
|
if shouldDropNoReply(response) {
|
||||||
suppressed = true
|
suppressed = true
|
||||||
} else {
|
} else {
|
||||||
al.bus.PublishOutbound(bus.OutboundMessage{
|
clean := stripReplyTags(response)
|
||||||
Channel: msg.Channel,
|
if al.shouldSuppressOutbound(msg, clean) {
|
||||||
ChatID: msg.ChatID,
|
suppressed = true
|
||||||
Content: response,
|
} else {
|
||||||
})
|
al.bus.PublishOutbound(bus.OutboundMessage{
|
||||||
|
Channel: msg.Channel,
|
||||||
|
ChatID: msg.ChatID,
|
||||||
|
Content: clean,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
al.audit.Record(trigger, msg.Channel, msg.SessionKey, suppressed, err)
|
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,
|
"chat_id": msg.ChatID,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
msg.Content = rewriteSystemMessageContent(msg.Content)
|
||||||
|
|
||||||
// Parse origin from chat_id (format: "channel:chat_id")
|
// Parse origin from chat_id (format: "channel:chat_id")
|
||||||
var originChannel, originChatID string
|
var originChannel, originChatID string
|
||||||
if idx := strings.Index(msg.ChatID, ":"); idx > 0 {
|
if idx := strings.Index(msg.ChatID, ":"); idx > 0 {
|
||||||
@@ -919,6 +926,39 @@ func extractFirstSourceLine(text string) string {
|
|||||||
return ""
|
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 {
|
func alSessionListForTool(sm *session.SessionManager, limit int) []tools.SessionInfo {
|
||||||
items := sm.List(limit)
|
items := sm.List(limit)
|
||||||
out := make([]tools.SessionInfo, 0, len(items))
|
out := make([]tools.SessionInfo, 0, len(items))
|
||||||
|
|||||||
Reference in New Issue
Block a user