CopilotKit/CopilotKit · warning

[CopilotKit] Tool arguments parsed to non-object (${typeof t

Error message

[CopilotKit] Tool arguments parsed to non-object (${typeof toolCall.function.arguments}), falling back to empty object

What it means

Server-side counterpart of the client fallback: in the v1-deprecated GraphQL runtime, when tool call arguments are neither a string nor a non-null object (undefined, null, number, boolean), the converter warns with the actual typeof and uses an empty object. Purely defensive handling of non-conforming tool call payloads.

Source

Thrown at packages/runtime/src/v1-deprecated/graphql/message-conversion/agui-to-gql.ts:273

    // Expected case: arguments is a JSON string
    try {
      argumentsObj = JSON.parse(toolCall.function.arguments);
    } catch {
      console.warn(
        `[CopilotKit] Failed to parse tool arguments, falling back to empty object`,
      );
      // Provide fallback empty object to prevent application crash
      argumentsObj = {};
    }
  } else if (
    typeof toolCall.function.arguments === "object" &&
    toolCall.function.arguments !== null
  ) {
    // Backward compatibility: arguments is already an object
    argumentsObj = toolCall.function.arguments;
  } else {
    // Fallback for undefined, null, or other types
    console.warn(
      `[CopilotKit] Tool arguments parsed to non-object (${typeof toolCall.function.arguments}), falling back to empty object`,
    );
    argumentsObj = {};
  }

  // Guard against successfully parsed non-object values (e.g. JSON.parse('""') → "")
  if (
    typeof argumentsObj !== "object" ||
    argumentsObj === null ||
    Array.isArray(argumentsObj)
  ) {
    console.warn(
      `[CopilotKit] Tool arguments parsed to non-object (${typeof argumentsObj}), falling back to empty object`,
    );
    argumentsObj = {};
  }

  // Always include name and arguments

View on GitHub (pinned to 68fbe97d87)

Solutions

  1. Always set function.arguments to at least "{}" in agent-emitted tool calls
  2. Align agent SDK and @copilotkit/runtime versions so the AG-UI message shape matches
  3. Validate tool call messages in agent tests before sending
  4. Guard tool handlers against empty arguments

Example fix

// before: agent emits { name: "done" } with no arguments
// after
{ name: "done", arguments: JSON.stringify({}) }
Defensive patterns

Strategy: validation

Validate before calling

if (typeof tc.function.arguments !== "string") {
  tc.function.arguments = JSON.stringify(tc.function.arguments ?? {});
}

Type guard

const isToolCallShapeOk = (tc: any): boolean =>
  tc?.function != null && (typeof tc.function.arguments === "string" || typeof tc.function.arguments === "object");

Prevention

When it happens

Trigger: A tool call message whose function.arguments field is missing (undefined), null, or a primitive reaches the v1 runtime's message conversion — e.g. a custom AG-UI agent that omits arguments for parameterless tools.

Common situations: Custom agent implementations skipping the arguments field; protocol drift between agent SDK versions; test harnesses constructing tool call messages by hand.

Related errors


AI-assisted analysis of CopilotKit/CopilotKit@68fbe97d87 (2026-08-27). Data as JSON: /api/errors/064f3600c5d12475. Report an issue: GitHub.