diff --git a/pkg/agent/agent_utils.go b/pkg/agent/agent_utils.go index 8e42c1493..67524b79c 100644 --- a/pkg/agent/agent_utils.go +++ b/pkg/agent/agent_utils.go @@ -172,10 +172,6 @@ func toolFeedbackExplanationFromMessages(messages []providers.Message) string { } func toolFeedbackArgsPreview(args map[string]any, maxLen int) string { - if args == nil { - args = map[string]any{} - } - argsJSON := utils.FormatArgsJSON(args, true, false) return utils.Truncate(argsJSON, maxLen) } diff --git a/pkg/agent/pipeline_execute.go b/pkg/agent/pipeline_execute.go index e1be2a74b..0cf3eaa9a 100644 --- a/pkg/agent/pipeline_execute.go +++ b/pkg/agent/pipeline_execute.go @@ -91,7 +91,7 @@ toolLoop: feedbackMsg := utils.FormatToolFeedbackMessage( toolName, toolFeedbackExplanation, -toolFeedbackArgsPreview(toolArgs, toolFeedbackMaxLen), + toolFeedbackArgsPreview(toolArgs, toolFeedbackMaxLen), ) fbCtx, fbCancel := context.WithTimeout(turnCtx, 3*time.Second) _ = al.bus.PublishOutbound(fbCtx, outboundMessageForTurnWithKind(ts, feedbackMsg, messageKindToolFeedback)) diff --git a/pkg/utils/tool_feedback.go b/pkg/utils/tool_feedback.go index 4e80e57f3..1834d7f78 100644 --- a/pkg/utils/tool_feedback.go +++ b/pkg/utils/tool_feedback.go @@ -10,6 +10,11 @@ import ( const ToolFeedbackContinuationHint = "Continuing the current task." func FormatArgsJSON(args map[string]any, prettyPrint, disableEscapeHTML bool) string { + // Normalize nil to empty map for consistent output + if args == nil { + args = map[string]any{} + } + var buf bytes.Buffer enc := json.NewEncoder(&buf) if prettyPrint { @@ -19,7 +24,8 @@ func FormatArgsJSON(args map[string]any, prettyPrint, disableEscapeHTML bool) st enc.SetEscapeHTML(false) } if err := enc.Encode(args); err != nil { - return "{}" + // Fallback to fmt.Sprintf to preserve visibility of problematic args + return fmt.Sprintf("%v", args) } return strings.TrimSpace(buf.String()) } diff --git a/pkg/utils/tool_feedback_test.go b/pkg/utils/tool_feedback_test.go index 5fabd3d83..da4accce4 100644 --- a/pkg/utils/tool_feedback_test.go +++ b/pkg/utils/tool_feedback_test.go @@ -143,7 +143,7 @@ func TestFormatArgsJSON_EscapeHTMLByDefault(t *testing.T) { func TestFormatArgsJSON_NilArgs(t *testing.T) { got := FormatArgsJSON(nil, false, false) - want := `null` + want := `{}` if got != want { t.Fatalf("FormatArgsJSON() nil = %q, want %q", got, want) }