siyuan-note/siyuan · error

invalid capability arguments: %w

Error message

invalid capability arguments: %w

What it means

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.

Source

Thrown at kernel/agent/agent.go:1213

				for i, tc := range aggregatedToolCalls {
					args := parsedArgs[i]
					registration := roundCapabilities.registration(tc.Function.Name)
					action := ""
					if a, ok := args["action"]; ok {
						action, _ = a.(string)
					}

					sendEvent(ch, AgentEvent{
						Type:       "tool_call",
						Name:       tc.Function.Name,
						RoundID:    roundID,
						ToolCallID: tc.ID,
						Arguments:  args,
					})

					toolInputErr := parseErrors[i]
					if toolInputErr != nil {
						toolInputErr = fmt.Errorf("invalid capability arguments: %w", toolInputErr)
					} else {
						toolInputErr = validateCapabilityCall(ctx, registration, args)
					}
					requiresConfirm, forcedConfirm := false, false
					if toolInputErr == nil {
						requiresConfirm, forcedConfirm = capabilityConfirmRequirement(
							registration, action, args, permissionController.allowSession.Load(), nil)
					}
					if requiresConfirm {
						confirmID := fmt.Sprintf("%s_%s_%d", turn.TurnID, tc.ID, i)
						ch2 := make(chan confirmResult, 1)
						confirmChannelsMu.Lock()
						confirmChannels[confirmID] = &confirmWaiter{sessionID: sessionID, ch: ch2}
						confirmChannelsMu.Unlock()
						effects := capabilityEffects(registration, action)
						sendCriticalEvent(ctx, ch, AgentEvent{
							Type: "confirm", Name: tc.Function.Name, Arguments: args, ConfirmID: confirmID, Effects: effects,
							ForcedConfirm: forcedConfirm, CapabilityID: registration.ID,

View on GitHub (pinned to 8641553a1f)

Solutions

  1. Read the wrapped cause to see the exact JSON parse error
  2. Retry the request — malformed JSON from the model is often transient
  3. Use a stronger model or lower temperature for tool-call reliability
  4. Verify the capability's argument schema is registered correctly and unchanged
  5. Ensure tool-call prompts/examples match the current schema
Defensive patterns

Strategy: try-catch

Validate before calling

var args map[string]any
if err := json.Unmarshal([]byte(rawArgs), &args); err != nil {
    // invalid arguments before the agent even sees them
}

Try / catch

var perr *json.SyntaxError
if errors.As(err, &perr) {
    // surface perr.Offset/Msg to the model so it can correct the JSON
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11). Data as JSON: /api/errors/773f5bb9f099198e. Report an issue: GitHub.