{"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":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/agent.go","lineNumber":1213,"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":1195,"sourceCodeEnd":1231,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/agent/agent.go#L1195-L1231","documentation":"When the agent dispatches tool (capability) calls, each call's JSON arguments are parsed before execution; a parse failure is wrapped as \"invalid capability arguments: %w\" and attached to the tool result instead of aborting the run. It indicates the model produced arguments that are not valid JSON for that capability.","triggerScenarios":"parseErrors[i] is non-nil for tool call i while processing the model's tool_calls in the agent loop; the raw parse error is wrapped and returned as the tool message content for that ToolCallID.","commonSituations":"Model emits truncated or malformed JSON arguments; single quotes or trailing commas in generated JSON; arguments schema changed after a capability update so the model's learned format no longer matches.","solutions":["Read the wrapped cause to see the exact JSON parse error","Retry the request — malformed JSON from the model is often transient","Use a stronger model or lower temperature for tool-call reliability","Verify the capability's argument schema is registered correctly and unchanged","Ensure tool-call prompts/examples match the current schema"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"var args map[string]any\nif err := json.Unmarshal([]byte(rawArgs), &args); err != nil {\n    // invalid arguments before the agent even sees them\n}","typeGuard":null,"tryCatchPattern":"var perr *json.SyntaxError\nif errors.As(err, &perr) {\n    // surface perr.Offset/Msg to the model so it can correct the JSON\n}","preventionTips":["Keep capability argument schemas simple and documented","Prefer models known for reliable structured output / tool calls","Return the parse error text as the tool result so the model can self-correct"],"tags":["agent","tools","json","arguments"],"backgroundTag":"json-parse-error","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}