Skip to content

Conversation

@ertembiyik
Copy link

@ertembiyik ertembiyik commented Sep 22, 2025

Summary

Some models on OpenRouter called tools with empty object params using "" instead of {}, when headed to traces, it's clear that agent is calling tools with empty args:

{
  "callId": "toolu_vrtx_019cputrBMsRPi8nKmGGjS1y",
  "name": "LINEAR_LIST_LINEAR_PROJECTS",
  "type": "function_call",
  "arguments": "",
  "providerData": {
    ...
  },
  "status": "completed"
}

This results in error:

ToolCallError: Failed to run function tools: SyntaxError: Unexpected end of JSON input

Example

Here is a minimal reproducible example:

agents-bug.zip

import { Agent, run } from "@openai/agents";
import { aisdk } from "@openai/agents-extensions";
import { createOpenRouter } from "@openrouter/ai-sdk-provider";
import { Composio } from "@composio/core";
import { OpenAIAgentsProvider } from "@composio/openai-agents";

// Replace these placeholder values with your real credentials before running the example.
const OPENROUTER_API_KEY = "";
const COMPOSIO_API_KEY = "";
const COMPOSIO_USER_ID = "";

async function main() {
    if (
        [OPENROUTER_API_KEY, COMPOSIO_API_KEY, COMPOSIO_USER_ID].some((value) =>
            value === ""
        )
    ) {
        throw new Error("Update the API key placeholders before running this example.");
    }
    const composio = new Composio({
        apiKey: COMPOSIO_API_KEY,
        provider: new OpenAIAgentsProvider({ strict: true }),
    });
    const linearTool = await composio.tools.get(COMPOSIO_USER_ID, {
        toolkits: ["LINEAR"]
    });
    const openrouter = createOpenRouter({
        apiKey: OPENROUTER_API_KEY,
    });
    const model = aisdk(openrouter("anthropic/claude-sonnet-4"));
    const agent = new Agent({
        name: "Linear Projects Agent",
        instructions: "Use the Linear tool to list projects and summarize them for the user.",
        model,
        tools: linearTool,
    });
    console.log("Running agent with LINEAR_LIST_LINEAR_PROJECTS...");
    const result = await run(agent, "List all projects in the connected Linear workspace.");
    console.log("Final agent output:", result.finalOutput ?? "No final output.");
}

main().catch((error) => {
    console.error("Agent execution failed:", error);
});
  1. Replace variable at the top with real values
  2. Run install and dev scripts:
pnpm i
pnpm run dev

Changes

  • Compare the tool params type from schema to the actual call and map "" to {} if needed

Tests

  • New tests validate both tools and handoffs for mapping "" to {} where appropriate

@changeset-bot
Copy link

changeset-bot bot commented Sep 22, 2025

🦋 Changeset detected

Latest commit: 938a841

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@openai/agents-extensions Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@ertembiyik
Copy link
Author

Related to vercel/ai#6687

@seratch seratch changed the title fix: open ai compatible models misuse '' in tools arguments call when… fix: non-OpenAI models w/ OpenRouter sends an empty string when calling tools Sep 22, 2025
@seratch seratch changed the title fix: non-OpenAI models w/ OpenRouter sends an empty string when calling tools fix: non-OpenAI models w/ OpenRouter send an empty string when calling tools Sep 22, 2025
@seratch
Copy link
Member

seratch commented Sep 22, 2025

Thanks for sending this, but I am unsure if this should be done on this SDK side.

@seratch seratch marked this pull request as draft September 25, 2025 06:27
@github-actions
Copy link
Contributor

github-actions bot commented Oct 6, 2025

This PR is stale because it has been open for 10 days with no activity.

@github-actions github-actions bot added the stale label Oct 6, 2025
@walkerheathr24-rgb
Copy link

Thank you for all of the help! I wasn't able to get to it sooner due have a procedure. It is the 9th one this year so that I really appreciate all of the support on this!

@github-actions github-actions bot removed the stale label Oct 8, 2025
@github-actions
Copy link
Contributor

This PR is stale because it has been open for 10 days with no activity.

@github-actions github-actions bot added the stale label Oct 19, 2025
@seratch seratch marked this pull request as ready for review October 25, 2025 01:16
@seratch
Copy link
Member

seratch commented Oct 25, 2025

@ertembiyik I haven't checked this for a while, but doesn't the latest ai-sdk still handle this pattern in a good way? If yes, we may consider having this workaround on our side.

@seratch seratch removed the stale label Oct 25, 2025
@ertembiyik
Copy link
Author

@ertembiyik I haven't checked this for a while, but doesn't the latest ai-sdk still handle this pattern in a good way? If yes, we may consider having this workaround on our side.

hey! let me check it today with ai-sdk/provider version 3 and come back

@ertembiyik
Copy link
Author

ertembiyik commented Oct 25, 2025

upd: i have tested the issue against ai sdk v6.0.0-beta.72 and @ai-sdk/provider v3.0.0-beta.8

the issue is still reproducible, i have simplified the example to not include composio, im now using a tool from @openai/agents with an empty object

important to mention that this issue seems to be reproducible on anthropic/claude-sonnet-4 model from openrouter, though on x-ai/grok-4-fast it seems to work just fine

here is the example i used:
agents-bug-ai-sdk-v6.zip

@ertembiyik
Copy link
Author

ertembiyik commented Oct 25, 2025

but i believe you are right that this is not the place for such patch, it should be done in openrouter sdk or ai sdk itself i guess

did one more test, where i took pure ai sdk solution w/ openrouter without relying on agents sdk. it did fine for anthropic/claude-sonnet-4 in the exact same empty object case

here it is:
agents-bug-pure-ai-sdk.zip

with that said, seems like the agents sdk is the source of the issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants