mistral_adapter

Mistral LLM adapter for Pipecat.

Mistral’s API uses an OpenAI-compatible interface but imposes three conversation-history constraints that OpenAI does not:

  1. Tool messages must be followed by an assistant message. A "tool" role message that isn’t followed by an "assistant" message is rejected.

  2. Only the initial contiguous system block is permitted. A "system" message appearing after any non-system message must be converted to "user".

  3. A trailing assistant message requires ``prefix=True``. When the conversation ends on an assistant message, Mistral expects the prefix flag set so it can continue from that partial reply.

This adapter extends OpenAILLMAdapter and applies those three fixups before the messages reach build_chat_completion_params.

class pipecat.adapters.services.mistral_adapter.MistralLLMAdapter[source]

Bases: OpenAILLMAdapter

Adapter that transforms messages to satisfy Mistral’s API constraints.

Mistral accepts the OpenAI chat-completions schema but enforces extra rules on conversation history. This adapter extends OpenAILLMAdapter and rewrites the messages produced by the parent to comply with those rules before the request is built.

get_llm_invocation_params(context: LLMContext, *, system_instruction: str | None = None, convert_developer_to_user: bool) OpenAILLMInvocationParams[source]

Get OpenAI-compatible invocation parameters with Mistral message fixes applied.

Parameters:
  • context – The LLM context containing messages, tools, etc.

  • system_instruction – Optional system instruction from service settings or run_inference. Forwarded to the parent adapter.

  • convert_developer_to_user – If True, convert “developer”-role messages to “user”-role messages. Forwarded to the parent adapter.

Returns:

Dictionary of parameters for Mistral’s ChatCompletion API, with messages transformed to satisfy Mistral’s constraints.