#[non_exhaustive]pub enum MessageRole {
System,
User,
Assistant,
Tool,
}Expand description
Role of a message in an LLM conversation.
Each role has specific semantics that LLM providers understand:
MessageRole::System: Instructions that guide the model’s behaviorMessageRole::User: Input from the human userMessageRole::Assistant: Responses from the AI modelMessageRole::Tool: Results from tool/function executions
§Example
use multi_llm::{MessageRole, UnifiedMessage};
// Explicit role usage
let msg = UnifiedMessage::simple(MessageRole::User, "Hello!");
// Or use convenience constructors (preferred)
let msg = UnifiedMessage::user("Hello!");Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
System
System instructions that guide the model’s behavior.
System messages typically contain:
- Persona definitions (“You are a helpful assistant”)
- Behavioral constraints (“Never reveal confidential information”)
- Output format instructions (“Respond in JSON format”)
User
Input from the human user.
User messages contain the actual queries, questions, or commands that the model should respond to.
Assistant
Response from the AI assistant.
Assistant messages are typically generated by the LLM but can also be provided as conversation history or to demonstrate expected output.
Tool
Result from a tool/function execution.
Tool messages contain the output of function calls. They must reference
the tool_call_id of the corresponding tool call from an assistant message.
Trait Implementations§
Source§impl Clone for MessageRole
impl Clone for MessageRole
Source§fn clone(&self) -> MessageRole
fn clone(&self) -> MessageRole
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MessageRole
impl Debug for MessageRole
Source§impl<'de> Deserialize<'de> for MessageRole
impl<'de> Deserialize<'de> for MessageRole
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for MessageRole
impl Display for MessageRole
Source§impl Hash for MessageRole
impl Hash for MessageRole
Source§impl PartialEq for MessageRole
impl PartialEq for MessageRole
Source§impl Serialize for MessageRole
impl Serialize for MessageRole
impl Eq for MessageRole
impl StructuralPartialEq for MessageRole
Auto Trait Implementations§
impl Freeze for MessageRole
impl RefUnwindSafe for MessageRole
impl Send for MessageRole
impl Sync for MessageRole
impl Unpin for MessageRole
impl UnwindSafe for MessageRole
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.