vercel / ai

Build AI-powered applications with React, Svelte, Vue, and Solid
https://sdk.vercel.ai/docs
Other
9.84k stars 1.46k forks source link

Model tried to call unavailable tool #1922

Closed JasonDevTech closed 4 months ago

JasonDevTech commented 4 months ago

Description

I am using tools and it seems around 35% of the time I get the following error:

NoSuchToolError [AI_NoSuchToolError]: Model tried to call unavailable tool 'multi_tool_use.parallel'. Available tools: search_joke, search_image at parseToolCall (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:1353:11) at eval (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:1417:26) at Array.map (<anonymous>) at generateText (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:1416:82)

Is this an expected error? I cannot pinpoint the root cause of this issue.

Code example

import { createOpenAI } from '@ai-sdk/openai';
import { generateText, streamText } from 'ai';

const openai = createOpenAI({  compatibility: 'strict'  });

const toolsCompletion = await generateText({
    model: openai(OPEN_AI_MODEL),
    maxTokens: 4096,
    system: 'Some prompt',
    maxToolRoundtrips: 5,
    toolChoice: 'required',
    tools,
    messages
});

completion = await streamText({
    model: openai(OPEN_AI_MODEL),
    maxTokens: 4096,
    system: 'Some prompt',
    messages: toolsCompletion.responseMessages
});

return completion.toTextStreamResponse();

Additional context

AI SDK @ 3.1.30

lgrammel commented 4 months ago

This means that the model is trying to call a tool that does not exist. It seems to be an OpenAI issue:

https://community.openai.com/t/model-tries-to-call-unknown-function-multi-tool-use-parallel/490653

someguy9 commented 3 months ago

Same here Jason

wong2 commented 2 months ago

same

lgrammel commented 2 months ago

Just read through the OpenAI thread again. One potential workaround could be to disable parallel tool calling. Is that an option for you?

wong2 commented 2 months ago

Is there an options for disable parallel tool calling in AI SDK?

lgrammel commented 2 months ago

@wong2 this issue is specific to openai chat models. you can configure parallelToolCalls for those: https://sdk.vercel.ai/providers/ai-sdk-providers/openai#chat-models

wong2 commented 2 months ago

@lgrammel Thanks!