Support provider-defined tools#1466
Conversation
🦋 Changeset detectedLatest commit: 86b45c0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
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 |
| const tool = toolCtx[toolCall.name]!; | ||
| if (!isFunctionTool(tool)) { | ||
| return FunctionCallOutput.create({ | ||
| callId: toolCall.callId, | ||
| output: `Unknown function tool: ${toolCall.name}`, | ||
| isError: true, | ||
| }); | ||
| } |
There was a problem hiding this comment.
🔴 executeToolCall crashes with TypeError when tool name is not found in toolCtx
The new isFunctionTool(tool) guard at line 196 is intended to gracefully handle non-function tools (returning an error FunctionCallOutput), but when toolCall.name doesn't exist in toolCtx, tool is undefined at runtime (the ! at line 195 is just a TS assertion). isFunctionTool(undefined) then throws a TypeError because tool_context.ts:376 accesses tool[FUNCTION_TOOL_SYMBOL] without a null guard—the short-circuit on line 375 only protects tool[TOOL_SYMBOL], not the next line. The graceful error path at lines 197–201 is never reached.
This can be triggered when an LLM hallucinates a tool name. Compare with the safe pattern in agents/src/voice/generation.ts:955-967 which has if (!tool) { ... continue; } before calling isFunctionTool.
| const tool = toolCtx[toolCall.name]!; | |
| if (!isFunctionTool(tool)) { | |
| return FunctionCallOutput.create({ | |
| callId: toolCall.callId, | |
| output: `Unknown function tool: ${toolCall.name}`, | |
| isError: true, | |
| }); | |
| } | |
| const tool = toolCtx[toolCall.name]; | |
| if (!tool || !isFunctionTool(tool)) { | |
| return FunctionCallOutput.create({ | |
| callId: toolCall.callId, | |
| output: `Unknown function tool: ${toolCall.name}`, | |
| isError: true, | |
| }); | |
| } |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Testing
pnpm exec prettier --write ...pnpm --filter @livekit/agents buildpnpm --filter @livekit/agents-plugin-mistralai buildpnpm --filter @livekit/agents-plugin-openai build(JS bundling succeeds; declaration step fails because optional test workspace deps are missing in this checkout:@livekit/agents-plugins-test,@livekit/agents-plugin-silero)pnpm --filter @livekit/agents-plugin-google build(JS bundling succeeds; declaration step fails because optional test workspace deps / OpenAI declarations are missing)pnpm --filter @livekit/agents-plugin-xai build(JS bundling succeeds; declaration step fails because optional test workspace deps / OpenAI declarations are missing)pnpm --filter @livekit/agents lint(warnings only, existing repo warnings)pnpm --filter @livekit/agents-plugin-openai lint(warnings only)pnpm --filter @livekit/agents-plugin-google lint(warnings only)pnpm --filter @livekit/agents-plugin-xai lint(warnings only)pnpm --filter @livekit/agents-plugin-mistralai lint