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

During AG-UI to GraphQL conversion, tool call arguments that are neither a string nor a non-null object (i.e. undefined, null, or an unexpected primitive like a number/boolean) hit the final fallback branch: the library warns with the actual typeof and substitutes an empty object. This is a defensive guard for non-conforming agent payloads.

Source

Thrown at packages/runtime-client-gql/src/message-conversion/agui-to-gql.ts:221

    // 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. Make your agent always populate toolCall.function.arguments with at least JSON.stringify({}) for parameterless tools
  2. If writing fixtures/tests, set arguments: "{}" on every tool call
  3. Upgrade @copilotkit/runtime-client-gql and your agent SDK to matching AG-UI protocol versions
  4. Ensure tool handlers validate required arguments so a {} call fails loudly

Example fix

// before (custom agent): arguments omitted
{ id: "call_1", type: "function", function: { name: "ping" } }

// after
{ id: "call_1", type: "function", function: { name: "ping", arguments: "{}" } }
Defensive patterns

Strategy: validation

Validate before calling

// before sending a tool call message
if (!toolCall.function.arguments) toolCall.function.arguments = JSON.stringify({});

Type guard

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

Prevention

When it happens

Trigger: toolCall.function.arguments is undefined (tool call message missing the arguments field), explicitly null, or a raw number/boolean — anything where typeof is not 'string' and not 'object'. Occurs in aguiToolCallToGQLActionExecution when converting the tool call message into an ActionExecution.

Common situations: Hand-built AG-UI test fixtures omitting arguments; a custom agent implementation that leaves arguments undefined for parameterless tools; protocol version mismatch between agent and client where arguments became optional.

Related errors


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