From bcc3d447a188114a19c7f900be013e578b95d3c9 Mon Sep 17 00:00:00 2001 From: David Siewert Date: Sat, 25 Apr 2026 20:46:16 +0600 Subject: [PATCH] feat(agent): add pretty_print and disable_escape_html options for tool feedback - Add PrettyPrint and DisableEscapeHTML config options to ToolFeedbackConfig - Add FormatArgsJSON helper function with configurable pretty printing and HTML escaping - Add toolFeedbackArgsPreviewWithOptions to pass formatting options - Update pipeline_execute.go to use new formatting options for tool feedback This fixes the issue where '&&' would be displayed as '\u0026' in tool feedback messages and provides optional pretty-printing for better readability. --- pkg/agent/agent_utils.go | 9 +++++++++ pkg/agent/pipeline_execute.go | 4 ++-- pkg/config/config.go | 8 +++++--- pkg/config/defaults.go | 8 +++++--- pkg/utils/tool_feedback.go | 17 +++++++++++++++++ 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/pkg/agent/agent_utils.go b/pkg/agent/agent_utils.go index 4ba75cde4..90d9f43b9 100644 --- a/pkg/agent/agent_utils.go +++ b/pkg/agent/agent_utils.go @@ -184,6 +184,15 @@ func toolFeedbackArgsPreview(args map[string]any, maxLen int) string { return utils.Truncate(string(argsJSON), maxLen) } +func toolFeedbackArgsPreviewWithOptions(args map[string]any, maxLen int, prettyPrint, disableEscapeHTML bool) string { + if args == nil { + args = map[string]any{} + } + + argsJSON := utils.FormatArgsJSON(args, prettyPrint, disableEscapeHTML) + return utils.Truncate(argsJSON, maxLen) +} + func shouldPublishToolFeedback(cfg *config.Config, ts *turnState) bool { if ts == nil || ts.channel == "" || ts.opts.SuppressToolFeedback { return false diff --git a/pkg/agent/pipeline_execute.go b/pkg/agent/pipeline_execute.go index 0cf3eaa9a..ec3514f10 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), + toolFeedbackArgsPreviewWithOptions(toolArgs, toolFeedbackMaxLen, al.cfg.Agents.Defaults.ToolFeedback.PrettyPrint, al.cfg.Agents.Defaults.ToolFeedback.DisableEscapeHTML), ) fbCtx, fbCancel := context.WithTimeout(turnCtx, 3*time.Second) _ = al.bus.PublishOutbound(fbCtx, outboundMessageForTurnWithKind(ts, feedbackMsg, messageKindToolFeedback)) @@ -373,7 +373,7 @@ toolLoop: feedbackMsg := utils.FormatToolFeedbackMessage( toolName, toolFeedbackExplanation, - toolFeedbackArgsPreview(toolArgs, toolFeedbackMaxLen), + toolFeedbackArgsPreviewWithOptions(toolArgs, toolFeedbackMaxLen, al.cfg.Agents.Defaults.ToolFeedback.PrettyPrint, al.cfg.Agents.Defaults.ToolFeedback.DisableEscapeHTML), ) fbCtx, fbCancel := context.WithTimeout(turnCtx, 3*time.Second) _ = al.bus.PublishOutbound(fbCtx, outboundMessageForTurnWithKind(ts, feedbackMsg, messageKindToolFeedback)) diff --git a/pkg/config/config.go b/pkg/config/config.go index 6bb8d3ce6..0cbc6fead 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -247,9 +247,11 @@ type SubTurnConfig struct { } type ToolFeedbackConfig struct { - Enabled bool `json:"enabled" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_ENABLED"` - MaxArgsLength int `json:"max_args_length" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_MAX_ARGS_LENGTH"` - SeparateMessages bool `json:"separate_messages" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_SEPARATE_MESSAGES"` + Enabled bool `json:"enabled" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_ENABLED"` + MaxArgsLength int `json:"max_args_length" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_MAX_ARGS_LENGTH"` + SeparateMessages bool `json:"separate_messages" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_SEPARATE_MESSAGES"` + PrettyPrint bool `json:"pretty_print" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_PRETTY_PRINT"` + DisableEscapeHTML bool `json:"disable_escape_html" env:"PICOCLAW_AGENTS_DEFAULTS_TOOL_FEEDBACK_DISABLE_ESCAPE_HTML"` } type AgentDefaults struct { diff --git a/pkg/config/defaults.go b/pkg/config/defaults.go index f3aaca7ab..7725b040e 100644 --- a/pkg/config/defaults.go +++ b/pkg/config/defaults.go @@ -35,9 +35,11 @@ func DefaultConfig() *Config { SummarizeTokenPercent: 75, SteeringMode: "one-at-a-time", ToolFeedback: ToolFeedbackConfig{ - Enabled: false, - MaxArgsLength: 300, - SeparateMessages: false, + Enabled: false, + MaxArgsLength: 300, + SeparateMessages: false, + PrettyPrint: true, + DisableEscapeHTML: true, }, SplitOnMarker: false, }, diff --git a/pkg/utils/tool_feedback.go b/pkg/utils/tool_feedback.go index de7cb467e..4e80e57f3 100644 --- a/pkg/utils/tool_feedback.go +++ b/pkg/utils/tool_feedback.go @@ -1,12 +1,29 @@ package utils import ( + "bytes" + "encoding/json" "fmt" "strings" ) const ToolFeedbackContinuationHint = "Continuing the current task." +func FormatArgsJSON(args map[string]any, prettyPrint, disableEscapeHTML bool) string { + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + if prettyPrint { + enc.SetIndent("", " ") + } + if disableEscapeHTML { + enc.SetEscapeHTML(false) + } + if err := enc.Encode(args); err != nil { + return "{}" + } + return strings.TrimSpace(buf.String()) +} + // FormatToolFeedbackMessage renders a tool feedback message for chat channels. // It keeps the tool name on the first line for animation and can include both // a human explanation and the serialized tool arguments in the body.