diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index f6fc6616d..f8092f827 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -1249,7 +1249,7 @@ func formatMessageForSummary(msg providers.Message) []string { "assistant(tool_call id=%s name=%s): %s", tc.ID, name, - utils.Truncate(args, 240), + truncateSummaryField(args, 240), )) } @@ -1266,7 +1266,7 @@ func formatMessageForSummary(msg providers.Message) []string { if content == "" { return []string{fmt.Sprintf("tool(%s):", toolID)} } - return []string{fmt.Sprintf("tool(%s): %s", toolID, utils.Truncate(content, 320))} + return []string{fmt.Sprintf("tool(%s): %s", toolID, truncateSummaryField(content, 320))} case "user": fallthrough @@ -1275,6 +1275,14 @@ func formatMessageForSummary(msg providers.Message) []string { } } +func truncateSummaryField(content string, max int) string { + truncated := utils.Truncate(content, max) + if utf8.RuneCountInString(truncated) < utf8.RuneCountInString(content) { + return truncated + " [TRUNCATED]" + } + return truncated +} + // estimateTokens estimates the number of tokens in a message list. // Uses a safe heuristic of 2.5 characters per token to account for CJK and other // overheads better than the previous 3 chars/token.