fix(agent): harden tool parameter parsing against LLM type mismatches (#1505)
This commit is contained in:
@@ -69,8 +69,13 @@ func CastParams(args json.RawMessage, schema json.RawMessage) json.RawMessage {
|
|||||||
func castValue(val interface{}, targetType string) (interface{}, bool) {
|
func castValue(val interface{}, targetType string) (interface{}, bool) {
|
||||||
switch targetType {
|
switch targetType {
|
||||||
case "array":
|
case "array":
|
||||||
// Allow a single string to satisfy string-array parameters used by tools.
|
|
||||||
if s, ok := val.(string); ok {
|
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
|
return []string{s}, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@ type TodoWriteTool struct {
|
|||||||
|
|
||||||
// TodoWriteInput defines the input parameters for todo_write tool
|
// TodoWriteInput defines the input parameters for todo_write tool
|
||||||
type TodoWriteInput struct {
|
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"`
|
Steps []PlanStep `json:"steps" jsonschema:"Array of research plan steps with status tracking"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user