Everyone, when using ```from livekit.plugins impor...
# ask-ai
b
Everyone, when using
Copy code
from livekit.plugins import openai
to dynamically register tools, haven’t you run into some strange issues? I’ve encountered two odd problems and would like to share them: 1. "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn." 2. When tools are present and
tool_choice
is set to
auto
, if I ask a question outside of the tools, the model always replies that it doesn’t have that capability. I’d like to know whether this is an issue with the official plugin, or if I’m misusing it. I’ve followed the official examples exactly.
t
Thanks for reaching out, zhuyu. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
It looks like you're encountering the error "Please ensure that the number of function response parts is equal to the number of function call parts of the function call turn." This usually happens when there’s a mismatch between function calls and their responses during streaming. It can be a bit tricky, but it often means that the tool execution or response handling isn’t perfectly in sync. To get things back on track, try making sure that every function call has a matching response in the streaming process, and avoid any partial or orphaned responses. Also, double-check that the number of function call events matches the number of function response events during the same turn. About the
tool_choice="auto"
setting — this lets the model decide on its own whether to use a tool based on the flow of the conversation. So, if the model says it can’t handle a question outside the tools, it probably means it didn’t find any relevant tool for that query. If you want to tweak this behavior, you can set
tool_choice
to
"required"
to make sure a tool is always used,
"none"
to turn off tools entirely, or specify a particular tool name if you want to call a specific function directly. Lastly, if you’re working with the official examples, it’s really important to ensure all tools are properly defined using the
@function_tool
decorator with the right names and descriptions. This helps the model recognize and call the right functions smoothly. Sources: OpenAI LLM integration guide | LiveKit Docs | Tool definition and use | LiveKit Docs | plugins/openai/src/realtime/realtime_model.ts | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...