MessageRole
Defines the four message roles used in chat conversations with LLMs.Import
Type Definition
Values
| Value | Description |
|---|---|
'system' | System instructions that set the model’s behavior, persona, or constraints. Typically the first message in a conversation. |
'user' | Messages from the end user or application providing input to the model. |
'assistant' | Responses generated by the model, including text replies and tool call requests. |
'tool' | Responses from tool/function executions, returned after the model requests a tool call. |
Examples
Role-specific Messages
Filtering Messages by Role
Counting Messages by Role
Type Guard
Related
- PromptMessage — uses
MessageRoleas itsrolefield - MessageContent — content types carried by each message