Bug Description
I am experiencing an issue with the Mistral LLM plugin in LiveKit Agents when the last message in the ChatContext has the assistant role.
The issue is reproducible in at least two different scenarios:
- When a tool uses context.with_filler().
- When calling session.generate_reply() without providing user_input.
In both cases, the Mistral API rejects the request with HTTP 400 / error code 3230.
The same behavior does not occur with the Ollama LLM plugin.
Expected Behavior
session.generate_reply() should be able to generate a response even when the current ChatContext ends with an assistant message, provided that this is a valid LiveKit context.
For example:
user
assistant
followed by:
await session.generate_reply()
should result in a valid provider request.
Likewise, a filler message generated by context.with_filler() should not prevent the LLM from generating the response after a tool completes.
Reproduction Steps
Reproduction 1: with_filler()
A simplified tool looks like this:
@function_tool
async def my_tool(context: RunContext):
async with context.with_filler("One moment..."):
result = await do_something()
return result
The filler is added to the ChatContext as an assistant message.
After the tool returns, LiveKit attempts to generate the next LLM response.
At this point, the context can end with:
assistant: "One moment..."
The Mistral API then rejects the request:
Status 400
Expected last role User or Tool
(or Assistant with prefix True)
for serving but got assistant
type: invalid_request_error
code: 3230
Reproduction 2: generate_reply() without user_input
The issue can also be reproduced without with_filler().
For example, if the current ChatContext ends with an assistant message:
await session.generate_reply()
results in the same Mistral error:
Status 400
Expected last role User or Tool
(or Assistant with prefix True)
for serving but got assistant
type: invalid_request_error
code: 3230
However, adding a user_input makes the request valid:
await session.generate_reply(
user_input="Please continue."
)
This suggests that the issue is related to generating a new response when the last message in the context is an assistant message.
Operating System
macOS Tahoe 26.5.1
Models Used
Deepgram/Mistral/ElevenLabs
Package Versions
"livekit-api>=1.2.0",
"livekit-plugins-anthropic>=1.7.1",
"livekit-plugins-deepgram>=1.7.1",
"livekit-plugins-elevenlabs>=1.7.1",
"livekit-plugins-google>=1.7.1",
"livekit-plugins-mistralai>=1.7.1",
"livekit-plugins-openai>=1.7.1",
"livekit-plugins-silero>=1.7.1",
Session/Room/Call IDs
No response
Proposed Solution
Add a dummy user message as it is for the others providers that need it.
Additional Context
No response
Screenshots and Recordings
No response
Bug Description
I am experiencing an issue with the Mistral LLM plugin in LiveKit Agents when the last message in the ChatContext has the assistant role.
The issue is reproducible in at least two different scenarios:
In both cases, the Mistral API rejects the request with HTTP 400 / error code 3230.
The same behavior does not occur with the Ollama LLM plugin.
Expected Behavior
session.generate_reply() should be able to generate a response even when the current ChatContext ends with an assistant message, provided that this is a valid LiveKit context.
For example:
user
assistant
followed by:
await session.generate_reply()
should result in a valid provider request.
Likewise, a filler message generated by context.with_filler() should not prevent the LLM from generating the response after a tool completes.
Reproduction Steps
Operating System
macOS Tahoe 26.5.1
Models Used
Deepgram/Mistral/ElevenLabs
Package Versions
Session/Room/Call IDs
No response
Proposed Solution
Additional Context
No response
Screenshots and Recordings
No response