refactor: enhance AgentLoopEngine with confirmed MCP reply handling and add tests for tool result summarization

This commit is contained in:
mlogclub
2026-07-28 12:16:16 +08:00
parent 07370fe9a2
commit 1ea76e39f9
4 changed files with 178 additions and 2 deletions
@@ -98,5 +98,27 @@ func appendNonBlankSegment(input []string, value string) []string {
if value == "" {
return input
}
key := canonicalToolResultSegment(value)
for _, existing := range input {
if canonicalToolResultSegment(existing) == key {
return input
}
}
return append(input, value)
}
func canonicalToolResultSegment(value string) string {
value = strings.TrimSpace(value)
if value == "" {
return ""
}
var payload any
if err := json.Unmarshal([]byte(value), &payload); err != nil {
return value
}
data, err := json.Marshal(payload)
if err != nil {
return value
}
return string(data)
}