When i invoke a tool call but then i want to say s...
# ask-ai
a
When i invoke a tool call but then i want to say something (context.session.generate_reply) i receive the error: {"message": "Error in _llm_inference_task\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.11/site-packages/livekit/agents/inference/llm.py\", line 316, in _run\n async for chunk in stream:\n File \"/usr/local/lib/python3.11/site-packages/openai/_streaming.py\", line 146, in __aiter__\n async for item in self._iterator:\n File \"/usr/local/lib/python3.11/site-packages/openai/_streaming.py\", line 192, in __stream__\n raise APIError(\nopenai.APIError: Upstream error from Groq: Tool choice is none, but model called a tool\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.11/site-packages/livekit/agents/llm/llm.py\", line 190, in _main_task\n return await self._run()\n ^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.11/site-packages/livekit/agents/inference/llm.py\", line 349, in _run\n raise APIConnectionError(retryable=retryable) from e\nlivekit.agents._exceptions.APIConnectionError: Connection error. (body=None, retryable=True)\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/usr/local/lib/python3.11/site-packages/livekit/agents/utils/log.py\", line 16, in async_fn_logs\n return await fn(*args, **kwargs)\n ^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.11/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.11/site-packages/livekit/agents/voice/generation.py\", line 125, in _llm_inference_task\n async for chunk in llm_node:\n File \"/usr/local/lib/python3.11/site-packages/livekit/agents/voice/agent.py\", line 402, in llm_node\n async for chunk in stream:\n File \"/usr/local/lib/python3.11/site-packages/livekit/agents/llm/llm.py\", line 344, in __anext__\n raise exc # noqa: B904\n ^^^^^^^^^\n File \"/usr/local/lib/python3.11/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/usr/local/lib/python3.11/site-packages/livekit/agents/llm/llm.py\", line 202, in _main_task\n raise APIConnectionError(\nlivekit.agents._exceptions.APIConnectionError: failed to generate LLM completion after 4 attempts (body=None, retryable=True)", "level": "ERROR", "name": "livekit.agents", "pid": 250, "job_id": "AJ_KWfyuJ4pvpeh", "timestamp": "2025-11-09T221814.500317+00:00"}
t
Thanks for reaching out, Angel. 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 "Tool choice is none, but model called a tool" because the model is trying to use a tool even though the
tool_choice
is set to "none". This usually happens when there’s a little mismatch between how the model is set up and how it’s running. Here are some friendly steps to help you fix this: • Make sure to explicitly set
tool_choice="none"
in the
ModelSettings
when you call
context.session.generate_reply
. For example:
await context.session.generate_reply(model_settings=ModelSettings(tool_choice="none"))
• Try not to call
generate_reply
inside a function tool unless you’ve properly set
tool_choice
to "none". • Double-check that no tools are registered in the session if you intend to have
tool_choice="none"
. • Confirm that your LLM plugin (like OpenAI or Anthropic) honors the
tool_choice
parameter. • Look over your middleware or agent logic to ensure nothing is changing the
tool_choice
setting during execution. Following these tips should help you avoid this error. If you run into any more bumps or have questions, feel free to reach out—I’m here to help! Sources: Anthropic Claude LLM plugin guide | LiveKit docs | OpenAI LLM plugin guide | LiveKit Docs | Azure OpenAI LLM plugin guide | LiveKit docs | Telnyx LLM plugin guide | LiveKit Docs | livekit-plugins/livekit-plugins-aws/livekit/plugins/aws/experimental/realti...