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

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
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.

2 participants