{"record":{"id":"773f5bb9f099198e","repo":"siyuan-note/siyuan","slug":"invalid-capability-arguments-w-773f5b","errorCode":null,"errorMessage":"invalid capability arguments: %w","messagePattern":"invalid capability arguments: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/agent/agent.go","lineNumber":1216,"sourceCode":"\t\t\t\tfor i, tc := range aggregatedToolCalls {\n\t\t\t\t\targs := parsedArgs[i]\n\t\t\t\t\tregistration := roundCapabilities.registration(tc.Function.Name)\n\t\t\t\t\taction := \"\"\n\t\t\t\t\tif a, ok := args[\"action\"]; ok {\n\t\t\t\t\t\taction, _ = a.(string)\n\t\t\t\t\t}\n\n\t\t\t\t\tsendEvent(ch, AgentEvent{\n\t\t\t\t\t\tType:       \"tool_call\",\n\t\t\t\t\t\tName:       tc.Function.Name,\n\t\t\t\t\t\tRoundID:    roundID,\n\t\t\t\t\t\tToolCallID: tc.ID,\n\t\t\t\t\t\tArguments:  args,\n\t\t\t\t\t})\n\n\t\t\t\t\ttoolInputErr := parseErrors[i]\n\t\t\t\t\tif toolInputErr != nil {\n\t\t\t\t\t\ttoolInputErr = fmt.Errorf(\"invalid capability arguments: %w\", toolInputErr)\n\t\t\t\t\t} else {\n\t\t\t\t\t\ttoolInputErr = validateCapabilityCall(ctx, registration, args)\n\t\t\t\t\t}\n\t\t\t\t\trequiresConfirm, forcedConfirm := false, false\n\t\t\t\t\tif toolInputErr == nil {\n\t\t\t\t\t\trequiresConfirm, forcedConfirm = capabilityConfirmRequirement(\n\t\t\t\t\t\t\tregistration, action, args, permissionController.allowSession.Load(), nil)\n\t\t\t\t\t}\n\t\t\t\t\tif requiresConfirm {\n\t\t\t\t\t\tconfirmID := fmt.Sprintf(\"%s_%s_%d\", turn.TurnID, tc.ID, i)\n\t\t\t\t\t\tch2 := make(chan confirmResult, 1)\n\t\t\t\t\t\tconfirmChannelsMu.Lock()\n\t\t\t\t\t\tconfirmChannels[confirmID] = &confirmWaiter{sessionID: sessionID, ch: ch2}\n\t\t\t\t\t\tconfirmChannelsMu.Unlock()\n\t\t\t\t\t\teffects := capabilityEffects(registration, action)\n\t\t\t\t\t\tsendCriticalEvent(ctx, ch, AgentEvent{\n\t\t\t\t\t\t\tType: \"confirm\", Name: tc.Function.Name, Arguments: args, ConfirmID: confirmID, Effects: effects,\n\t\t\t\t\t\t\tForcedConfirm: forcedConfirm, CapabilityID: registration.ID,","sourceCodeStart":1198,"sourceCodeEnd":1234,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/agent/agent.go#L1198-L1234","documentation":"Wraps a JSON-parsing failure of a tool call's arguments into a toolInputErr with the message \"invalid capability arguments\". When the model returns a tool/capability call whose Arguments string cannot be parsed (parseErrors[i] != nil), the agent labels it and skips validation/execution, instead reporting the invalid arguments back to the model as a failed tool call.","triggerScenarios":"In agent.go (~line 1214-1216): the model emitted a tool call whose tc.Arguments JSON is malformed (syntax error, truncated JSON, wrong types), so the per-call parse produced parseErrors[i]; the raw parse error is then wrapped as fmt.Errorf(\"invalid capability arguments: %w\", toolInputErr).","commonSituations":"A weak or quantized model emits malformed JSON arguments (unescaped newlines/quotes, trailing commas); the model stream was truncated mid-arguments; a model emits arguments as plain text instead of JSON; tool argument schemas are large and the model rambles.","solutions":["Inspect the wrapped %w error to see the exact JSON parse failure position and fix the tool's parameter schema/description so the model emits valid JSON.","Use a stronger model or lower temperature to reduce malformed JSON output.","Enable the agent's tool-argument repair/retry path (feed the parse error back so the model re-issues the call).","Check the provider/stream handling for truncation — if arguments are cut off at the stream end, verify stream collection completes before parsing."],"exampleFix":"// before\ntoolInputErr := parseErrors[i]\nif toolInputErr != nil {\n    toolInputErr = fmt.Errorf(\"invalid capability arguments: %w\", toolInputErr)\n}\n// after: attempt a lenient repair pass before reporting failure\nargs, parseErr := parseToolArguments(tc.Arguments)\nif parseErr != nil {\n    args, parseErr = repairToolArguments(tc.Arguments)\n}\ntoolInputErr = parseErr","handlingStrategy":"validation","validationCode":"function hasValidToolArgs(call) {\n  try { JSON.parse(call.arguments); return true } catch { return false }\n}","typeGuard":"func isValidJSONObject(s string) bool {\n    var v any\n    return json.Unmarshal([]byte(s), &v) == nil\n}","tryCatchPattern":"args, err := parseToolArguments(tc.Arguments)\nif err != nil {\n    // feed the \"invalid capability arguments\" error back to the model so it re-issues the call\n    appendToolErrorMessage(tc.ID, err)\n}","preventionTips":["Keep tool parameter schemas small and explicitly typed.","Prefer stronger models for tool-heavy workflows.","Send parse failures back to the model for automatic self-correction.","Verify stream collection completes fully before parsing arguments."],"tags":["agent","tool-calls","json","llm"],"backgroundTag":"json-parse-error","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}