{"record":{"id":"064f3600c5d12475","repo":"CopilotKit/CopilotKit","slug":"copilotkit-tool-arguments-parsed-to-non-object-064f36","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/src/v1-deprecated/graphql/message-conversion/agui-to-gql.ts","lineNumber":273,"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":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/CopilotKit/CopilotKit/blob/68fbe97d87420bd84e8196965c71bd6e394a3f7a/packages/runtime/src/v1-deprecated/graphql/message-conversion/agui-to-gql.ts#L255-L291","documentation":"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.","triggerScenarios":"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.","commonSituations":"Custom agent implementations skipping the arguments field; protocol drift between agent SDK versions; test harnesses constructing tool call messages by hand.","solutions":["Always set function.arguments to at least \"{}\" in agent-emitted tool calls","Align agent SDK and @copilotkit/runtime versions so the AG-UI message shape matches","Validate tool call messages in agent tests before sending","Guard tool handlers against empty arguments"],"exampleFix":"// before: agent emits { name: \"done\" } with no arguments\n// after\n{ name: \"done\", arguments: JSON.stringify({}) }","handlingStrategy":"validation","validationCode":"if (typeof tc.function.arguments !== \"string\") {\n  tc.function.arguments = JSON.stringify(tc.function.arguments ?? {});\n}","typeGuard":"const isToolCallShapeOk = (tc: any): boolean =>\n  tc?.function != null && (typeof tc.function.arguments === \"string\" || typeof tc.function.arguments === \"object\");","tryCatchPattern":null,"preventionTips":["Normalize tool call messages through a single emit helper that guarantees the arguments field","Pin agent SDK and runtime to compatible versions","Include shape assertions in agent message tests"],"tags":["tool-arguments","type-validation","v1-deprecated"],"backgroundTag":"malformed-tool-call-arguments","analyzedSha":"68fbe97d87420bd84e8196965c71bd6e394a3f7a","analyzedAt":"2026-08-27T04:03:26.537Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}