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 argumentsView on GitHub (pinned to 68fbe97d87)
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
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
- 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
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
- [CopilotKit] Failed to parse tool arguments, falling back to
- [CopilotKit] Failed to parse tool arguments, falling back to
- [CopilotKit] Tool arguments parsed to non-object (${typeof t
- [CopilotKit] Tool arguments parsed to non-object (${typeof p
- [CopilotKit] Tool arguments parsed to non-object (${typeof a
AI-assisted analysis of CopilotKit/CopilotKit@68fbe97d87 (2026-08-27).
Data as JSON: /api/errors/6c3685c3afe87bf0.
Report an issue: GitHub.