{"record":{"id":"6c3685c3afe87bf0","repo":"CopilotKit/CopilotKit","slug":"copilotkit-tool-arguments-parsed-to-non-object-6c3685","errorCode":null,"errorMessage":"[CopilotKit] Tool arguments parsed to non-object (${typeof toolCall.function.arguments}), falling back to empty object","messagePattern":"\\[CopilotKit\\] Tool arguments parsed to non-object \\((.+?)\\), falling back to empty object","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/runtime-client-gql/src/message-conversion/agui-to-gql.ts","lineNumber":221,"sourceCode":"    // Expected case: arguments is a JSON string\n    try {\n      argumentsObj = JSON.parse(toolCall.function.arguments);\n    } catch {\n      console.warn(\n        `[CopilotKit] Failed to parse tool arguments, falling back to empty object`,\n      );\n      // Provide fallback empty object to prevent application crash\n      argumentsObj = {};\n    }\n  } else if (\n    typeof toolCall.function.arguments === \"object\" &&\n    toolCall.function.arguments !== null\n  ) {\n    // Backward compatibility: arguments is already an object\n    argumentsObj = toolCall.function.arguments;\n  } else {\n    // Fallback for undefined, null, or other types\n    console.warn(\n      `[CopilotKit] Tool arguments parsed to non-object (${typeof toolCall.function.arguments}), falling back to empty object`,\n    );\n    argumentsObj = {};\n  }\n\n  // Guard against successfully parsed non-object values (e.g. JSON.parse('\"\"') → \"\")\n  if (\n    typeof argumentsObj !== \"object\" ||\n    argumentsObj === null ||\n    Array.isArray(argumentsObj)\n  ) {\n    console.warn(\n      `[CopilotKit] Tool arguments parsed to non-object (${typeof argumentsObj}), falling back to empty object`,\n    );\n    argumentsObj = {};\n  }\n\n  // Always include name and arguments","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/CopilotKit/CopilotKit/blob/68fbe97d87420bd84e8196965c71bd6e394a3f7a/packages/runtime-client-gql/src/message-conversion/agui-to-gql.ts#L203-L239","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Make your agent always populate toolCall.function.arguments with at least JSON.stringify({}) for parameterless tools","If writing fixtures/tests, set arguments: \"{}\" on every tool call","Upgrade @copilotkit/runtime-client-gql and your agent SDK to matching AG-UI protocol versions","Ensure tool handlers validate required arguments so a {} call fails loudly"],"exampleFix":"// before (custom agent): arguments omitted\n{ id: \"call_1\", type: \"function\", function: { name: \"ping\" } }\n\n// after\n{ id: \"call_1\", type: \"function\", function: { name: \"ping\", arguments: \"{}\" } }","handlingStrategy":"validation","validationCode":"// before sending a tool call message\nif (!toolCall.function.arguments) toolCall.function.arguments = JSON.stringify({});","typeGuard":"const hasValidArgumentsField = (tc: any): boolean =>\n  typeof tc?.function?.arguments === \"string\" ||\n  (typeof tc?.function?.arguments === \"object\" && tc?.function?.arguments !== null);","tryCatchPattern":null,"preventionTips":["Always populate arguments (at minimum \"{}\") on every tool call","Keep agent SDK and runtime versions aligned","Validate outgoing AG-UI messages in agent test suites"],"tags":["tool-arguments","type-validation","agui-to-gql"],"backgroundTag":"malformed-tool-call-arguments","analyzedSha":"68fbe97d87420bd84e8196965c71bd6e394a3f7a","analyzedAt":"2026-08-27T04:03:26.537Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}