Principle:Mistralai Client python Message Construction
| Knowledge Sources | |
|---|---|
| Domains | NLP, API_Design |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
A structured message construction pattern that assembles typed conversation messages with role-based semantics for chat completion APIs.
Description
Message Construction is the process of creating typed message objects that represent a conversation between a user, system, and assistant. Each message has a role (system, user, assistant, or tool) and content (text, multimodal chunks, or tool results). This pattern follows the OpenAI-compatible chat format that Mistral AI adopts, enabling multi-turn conversations, system instructions, and multimodal inputs. Messages are ordered chronologically and form the context window for the language model.
Usage
Use this principle whenever preparing input for a chat completion or streaming request. Construct a list of messages that represents the conversation history, system instructions, and the current user query.
Theoretical Basis
The chat message format follows a role-based conversation structure:
- SystemMessage: Sets the model's behavior and constraints
- UserMessage: Contains the user's input (text, images, documents)
- AssistantMessage: Represents prior model responses (for multi-turn)
- ToolMessage: Returns results from function/tool calls
Messages are serialized as a list and sent to the API, where the model processes them as a conversation context.