mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-13 18:07:36 +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.",
|
||||
"sessions_none": "No sessions.",
|
||||
"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",
|
||||
"startup_compaction_note": "[startup-compaction] removed %d old messages, kept %d recent messages"
|
||||
},
|
||||
|
||||
@@ -45,9 +45,7 @@ type AgentLoop struct {
|
||||
langUpdatedTemplate string
|
||||
runtimeCompactionNote string
|
||||
startupCompactionNote string
|
||||
toolNoSubagents string
|
||||
toolNoSessions string
|
||||
toolUnsupportedAction string
|
||||
systemRewriteTemplate string
|
||||
audit *triggerAudit
|
||||
running bool
|
||||
}
|
||||
@@ -169,6 +167,7 @@ func NewAgentLoop(cfg *config.Config, msgBus *bus.MessageBus, provider providers
|
||||
langUpdatedTemplate: cfg.Agents.Defaults.Texts.LangUpdatedTemplate,
|
||||
runtimeCompactionNote: cfg.Agents.Defaults.Texts.RuntimeCompactionNote,
|
||||
startupCompactionNote: cfg.Agents.Defaults.Texts.StartupCompactionNote,
|
||||
systemRewriteTemplate: cfg.Agents.Defaults.Texts.SystemRewriteTemplate,
|
||||
audit: newTriggerAudit(workspace),
|
||||
running: false,
|
||||
}
|
||||
@@ -206,14 +205,15 @@ func (al *AgentLoop) Run(ctx context.Context) error {
|
||||
if shouldDropNoReply(response) {
|
||||
suppressed = true
|
||||
} else {
|
||||
clean := stripReplyTags(response)
|
||||
clean, replyToID := parseReplyTag(response)
|
||||
if al.shouldSuppressOutbound(msg, clean) {
|
||||
suppressed = true
|
||||
} else {
|
||||
al.bus.PublishOutbound(bus.OutboundMessage{
|
||||
Channel: msg.Channel,
|
||||
ChatID: msg.ChatID,
|
||||
Content: clean,
|
||||
Channel: msg.Channel,
|
||||
ChatID: msg.ChatID,
|
||||
Content: clean,
|
||||
ReplyToID: replyToID,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -564,7 +564,7 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe
|
||||
"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")
|
||||
var originChannel, originChatID string
|
||||
@@ -931,23 +931,28 @@ func shouldDropNoReply(text string) bool {
|
||||
return strings.EqualFold(t, "NO_REPLY")
|
||||
}
|
||||
|
||||
func stripReplyTags(text string) string {
|
||||
func parseReplyTag(text string) (content string, replyToID string) {
|
||||
t := strings.TrimSpace(text)
|
||||
if !strings.HasPrefix(t, "[[") {
|
||||
return text
|
||||
return text, ""
|
||||
}
|
||||
end := strings.Index(t, "]]")
|
||||
if end <= 0 {
|
||||
return text
|
||||
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:])
|
||||
rawTag := strings.TrimSpace(t[2:end])
|
||||
tag := strings.ToLower(rawTag)
|
||||
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)
|
||||
if !strings.HasPrefix(c, "[System Message]") {
|
||||
return content
|
||||
@@ -956,7 +961,14 @@ func rewriteSystemMessageContent(content string) string {
|
||||
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
|
||||
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 {
|
||||
|
||||
@@ -16,10 +16,11 @@ type Button struct {
|
||||
}
|
||||
|
||||
type OutboundMessage struct {
|
||||
Channel string `json:"channel"`
|
||||
ChatID string `json:"chat_id"`
|
||||
Content string `json:"content"`
|
||||
Buttons [][]Button `json:"buttons,omitempty"`
|
||||
Channel string `json:"channel"`
|
||||
ChatID string `json:"chat_id"`
|
||||
Content string `json:"content"`
|
||||
ReplyToID string `json:"reply_to_id,omitempty"`
|
||||
Buttons [][]Button `json:"buttons,omitempty"`
|
||||
}
|
||||
|
||||
type MessageHandler func(InboundMessage) error
|
||||
|
||||
@@ -53,6 +53,7 @@ type AgentTextConfig struct {
|
||||
SubagentsNone string `json:"subagents_none"`
|
||||
SessionsNone string `json:"sessions_none"`
|
||||
UnsupportedAction string `json:"unsupported_action"`
|
||||
SystemRewriteTemplate string `json:"system_rewrite_template"`
|
||||
RuntimeCompactionNote string `json:"runtime_compaction_note"`
|
||||
StartupCompactionNote string `json:"startup_compaction_note"`
|
||||
}
|
||||
@@ -293,6 +294,7 @@ func DefaultConfig() *Config {
|
||||
SubagentsNone: "No subagents.",
|
||||
SessionsNone: "No sessions.",
|
||||
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",
|
||||
StartupCompactionNote: "[startup-compaction] removed %d old messages, kept %d recent messages",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user