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
- 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
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
- 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
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
- This is not a valid .sy.zip archive. If the archive was expo
- host has no public IP:
- Failed to save agent session
- Failed to remove agent session
- Failed to update agent session permission
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/773f5bb9f099198e.
Report an issue: GitHub.