From d9ba7716b531d1c8e8d95b75c7fc5f0604c4c430 Mon Sep 17 00:00:00 2001 From: caiyuze-cpu <1253760535@qq.com> Date: Thu, 28 May 2026 07:50:26 +0800 Subject: [PATCH] fix(agent): harden tool parameter parsing against LLM type mismatches (#1505) --- internal/agent/tools/param_cast.go | 7 ++++++- internal/agent/tools/todo_write.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/agent/tools/param_cast.go b/internal/agent/tools/param_cast.go index 9b0cf4a9..a87199dd 100644 --- a/internal/agent/tools/param_cast.go +++ b/internal/agent/tools/param_cast.go @@ -69,8 +69,13 @@ func CastParams(args json.RawMessage, schema json.RawMessage) json.RawMessage { func castValue(val interface{}, targetType string) (interface{}, bool) { switch targetType { case "array": - // Allow a single string to satisfy string-array parameters used by tools. if s, ok := val.(string); ok { + // Try JSON parsing first (handles "[{...}]" → []interface{}) + var parsed []interface{} + if err := json.Unmarshal([]byte(s), &parsed); err == nil { + return parsed, true + } + // Fall back: single string → string array return []string{s}, true } diff --git a/internal/agent/tools/todo_write.go b/internal/agent/tools/todo_write.go index 97d83e71..570cd402 100644 --- a/internal/agent/tools/todo_write.go +++ b/internal/agent/tools/todo_write.go @@ -143,7 +143,7 @@ type TodoWriteTool struct { // TodoWriteInput defines the input parameters for todo_write tool type TodoWriteInput struct { - Task string `json:"task" jsonschema:"The complex task or question you need to create a plan for"` + Task string `json:"task,omitempty" jsonschema:"The complex task or question you need to create a plan for"` Steps []PlanStep `json:"steps" jsonschema:"Array of research plan steps with status tracking"` }