fix: improve error handling and nil consistency in FormatArgsJSON

- Use fmt.Sprintf fallback instead of {} on encoding errors
- Normalize nil args to {} in FormatArgsJSON for consistent output
- Update tests to expect {} instead of null for nil args

Based on PR #2670 review feedback from afjcjsbx
This commit is contained in:
David Siewert committed 2026-04-27 16:05:10 +06:00
1 parent 97b1c3efec
commit 8dca2a1319
4 files changed
+9 -7

No files matched your search

-4
View File
@@ -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)
}
+1 -1
View File
@@ -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))