diff --git a/pkg/agent/loop.go b/pkg/agent/loop.go index 6db8216..6f4aaed 100644 --- a/pkg/agent/loop.go +++ b/pkg/agent/loop.go @@ -345,7 +345,7 @@ func run(ctx context.Context, cfg agentConfig, state state) error { } if !isErr && cfg.ToolResultMaxBytes > 0 && len(result) > cfg.ToolResultMaxBytes { orig := len(result) - result = result[:cfg.ToolResultMaxBytes] + result = strings.ToValidUTF8(result[:cfg.ToolResultMaxBytes], "") result += fmt.Sprintf("\n\n[HARD LIMIT: %s output truncated — %d of %d bytes shown. This is a safety ceiling, not a semantic boundary.]", tc.Name, cfg.ToolResultMaxBytes, orig) }