mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-05-22 20:27:28 +08:00
add reply-tag metadata support and externalize system rewrite/dialog strings
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
"subagents_none": "No subagents.",
|
"subagents_none": "No subagents.",
|
||||||
"sessions_none": "No sessions.",
|
"sessions_none": "No sessions.",
|
||||||
"unsupported_action": "unsupported action",
|
"unsupported_action": "unsupported action",
|
||||||
|
"system_rewrite_template": "Rewrite the following internal system update in concise user-facing language:\n\n%s",
|
||||||
"runtime_compaction_note": "[runtime-compaction] removed %d old messages, kept %d recent messages",
|
"runtime_compaction_note": "[runtime-compaction] removed %d old messages, kept %d recent messages",
|
||||||
"startup_compaction_note": "[startup-compaction] removed %d old messages, kept %d recent messages"
|
"startup_compaction_note": "[startup-compaction] removed %d old messages, kept %d recent messages"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -45,9 +45,7 @@ type AgentLoop struct {
|
|||||||
langUpdatedTemplate string
|
langUpdatedTemplate string
|
||||||
runtimeCompactionNote string
|
runtimeCompactionNote string
|
||||||
startupCompactionNote string
|
startupCompactionNote string
|
||||||
toolNoSubagents string
|
systemRewriteTemplate string
|
||||||
toolNoSessions string
|
|
||||||
toolUnsupportedAction string
|
|
||||||
audit *triggerAudit
|
audit *triggerAudit
|
||||||
running bool
|
running bool
|
||||||
}
|
}
|
||||||
@@ -169,6 +167,7 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers
|
|||||||
langUpdatedTemplate: cfg.Agents.Defaults.Texts.LangUpdatedTemplate,
|
langUpdatedTemplate: cfg.Agents.Defaults.Texts.LangUpdatedTemplate,
|
||||||
runtimeCompactionNote: cfg.Agents.Defaults.Texts.RuntimeCompactionNote,
|
runtimeCompactionNote: cfg.Agents.Defaults.Texts.RuntimeCompactionNote,
|
||||||
startupCompactionNote: cfg.Agents.Defaults.Texts.StartupCompactionNote,
|
startupCompactionNote: cfg.Agents.Defaults.Texts.StartupCompactionNote,
|
||||||
|
systemRewriteTemplate: cfg.Agents.Defaults.Texts.SystemRewriteTemplate,
|
||||||
audit: newTriggerAudit(workspace),
|
audit: newTriggerAudit(workspace),
|
||||||
running: false,
|
running: false,
|
||||||
}
|
}
|
||||||
@@ -206,14 +205,15 @@ func (al *AgentLoop) Run(ctx context.Context) error {
|
|||||||
if shouldDropNoReply(response) {
|
if shouldDropNoReply(response) {
|
||||||
suppressed = true
|
suppressed = true
|
||||||
} else {
|
} else {
|
||||||
clean := stripReplyTags(response)
|
clean, replyToID := parseReplyTag(response)
|
||||||
if al.shouldSuppressOutbound(msg, clean) {
|
if al.shouldSuppressOutbound(msg, clean) {
|
||||||
suppressed = true
|
suppressed = true
|
||||||
} else {
|
} else {
|
||||||
al.bus.PublishOutbound(bus.OutboundMessage{
|
al.bus.PublishOutbound(bus.OutboundMessage{
|
||||||
Channel: msg.Channel,
|
Channel: msg.Channel,
|
||||||
ChatID: msg.ChatID,
|
ChatID: msg.ChatID,
|
||||||
Content: clean,
|
Content: clean,
|
||||||
|
ReplyToID: replyToID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -564,7 +564,7 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe
|
|||||||
"chat_id": msg.ChatID,
|
"chat_id": msg.ChatID,
|
||||||
})
|
})
|
||||||
|
|
||||||
msg.Content = rewriteSystemMessageContent(msg.Content)
|
msg.Content = rewriteSystemMessageContent(msg.Content, al.systemRewriteTemplate)
|
||||||
|
|
||||||
// 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
|
||||||
@@ -931,23 +931,28 @@ func shouldDropNoReply(text string) bool {
|
|||||||
return strings.EqualFold(t, "NO_REPLY")
|
return strings.EqualFold(t, "NO_REPLY")
|
||||||
}
|
}
|
||||||
|
|
||||||
func stripReplyTags(text string) string {
|
func parseReplyTag(text string) (content string, replyToID string) {
|
||||||
t := strings.TrimSpace(text)
|
t := strings.TrimSpace(text)
|
||||||
if !strings.HasPrefix(t, "[[") {
|
if !strings.HasPrefix(t, "[[") {
|
||||||
return text
|
return text, ""
|
||||||
}
|
}
|
||||||
end := strings.Index(t, "]]")
|
end := strings.Index(t, "]]")
|
||||||
if end <= 0 {
|
if end <= 0 {
|
||||||
return text
|
return text, ""
|
||||||
}
|
}
|
||||||
tag := strings.ToLower(strings.TrimSpace(t[2:end]))
|
rawTag := strings.TrimSpace(t[2:end])
|
||||||
if strings.HasPrefix(tag, "reply_to_current") || strings.HasPrefix(tag, "reply_to:") || strings.HasPrefix(tag, "reply_to") {
|
tag := strings.ToLower(rawTag)
|
||||||
return strings.TrimSpace(t[end+2:])
|
if strings.HasPrefix(tag, "reply_to_current") || strings.HasPrefix(tag, "reply_to") {
|
||||||
|
content = strings.TrimSpace(t[end+2:])
|
||||||
|
if strings.HasPrefix(tag, "reply_to:") {
|
||||||
|
replyToID = strings.TrimSpace(rawTag[len("reply_to:"):])
|
||||||
|
}
|
||||||
|
return content, replyToID
|
||||||
}
|
}
|
||||||
return text
|
return text, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func rewriteSystemMessageContent(content string) string {
|
func rewriteSystemMessageContent(content, template string) string {
|
||||||
c := strings.TrimSpace(content)
|
c := strings.TrimSpace(content)
|
||||||
if !strings.HasPrefix(c, "[System Message]") {
|
if !strings.HasPrefix(c, "[System Message]") {
|
||||||
return content
|
return content
|
||||||
@@ -956,7 +961,14 @@ func rewriteSystemMessageContent(content string) string {
|
|||||||
if body == "" {
|
if body == "" {
|
||||||
return "Please summarize the system event in concise user-facing language."
|
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
|
tpl := strings.TrimSpace(template)
|
||||||
|
if tpl == "" {
|
||||||
|
tpl = "Rewrite the following internal system update in concise user-facing language:\n\n%s"
|
||||||
|
}
|
||||||
|
if strings.Contains(tpl, "%s") {
|
||||||
|
return fmt.Sprintf(tpl, body)
|
||||||
|
}
|
||||||
|
return tpl + "\n\n" + body
|
||||||
}
|
}
|
||||||
|
|
||||||
func alSessionListForTool(sm *session.SessionManager, limit int) []tools.SessionInfo {
|
func alSessionListForTool(sm *session.SessionManager, limit int) []tools.SessionInfo {
|
||||||
|
|||||||
@@ -16,10 +16,11 @@ type Button struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OutboundMessage struct {
|
type OutboundMessage struct {
|
||||||
Channel string `json:"channel"`
|
Channel string `json:"channel"`
|
||||||
ChatID string `json:"chat_id"`
|
ChatID string `json:"chat_id"`
|
||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
Buttons [][]Button `json:"buttons,omitempty"`
|
ReplyToID string `json:"reply_to_id,omitempty"`
|
||||||
|
Buttons [][]Button `json:"buttons,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type MessageHandler func(InboundMessage) error
|
type MessageHandler func(InboundMessage) error
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ type AgentTextConfig struct {
|
|||||||
SubagentsNone string `json:"subagents_none"`
|
SubagentsNone string `json:"subagents_none"`
|
||||||
SessionsNone string `json:"sessions_none"`
|
SessionsNone string `json:"sessions_none"`
|
||||||
UnsupportedAction string `json:"unsupported_action"`
|
UnsupportedAction string `json:"unsupported_action"`
|
||||||
|
SystemRewriteTemplate string `json:"system_rewrite_template"`
|
||||||
RuntimeCompactionNote string `json:"runtime_compaction_note"`
|
RuntimeCompactionNote string `json:"runtime_compaction_note"`
|
||||||
StartupCompactionNote string `json:"startup_compaction_note"`
|
StartupCompactionNote string `json:"startup_compaction_note"`
|
||||||
}
|
}
|
||||||
@@ -293,6 +294,7 @@ func DefaultConfig() *Config {
|
|||||||
SubagentsNone: "No subagents.",
|
SubagentsNone: "No subagents.",
|
||||||
SessionsNone: "No sessions.",
|
SessionsNone: "No sessions.",
|
||||||
UnsupportedAction: "unsupported action",
|
UnsupportedAction: "unsupported action",
|
||||||
|
SystemRewriteTemplate: "Rewrite the following internal system update in concise user-facing language:\n\n%s",
|
||||||
RuntimeCompactionNote: "[runtime-compaction] removed %d old messages, kept %d recent messages",
|
RuntimeCompactionNote: "[runtime-compaction] removed %d old messages, kept %d recent messages",
|
||||||
StartupCompactionNote: "[startup-compaction] removed %d old messages, kept %d recent messages",
|
StartupCompactionNote: "[startup-compaction] removed %d old messages, kept %d recent messages",
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user