messages
Attribute AssistantContent
Type: TypeAlias
Type alias for content that can fit into an AssistantMessage.
Class AssistantMessage
An assistant message containing the model's response.
Attributes
| Name | Type | Description |
|---|---|---|
| role | Literal['assistant'] | The role of this message. Always "assistant". |
| content | Sequence[AssistantContentPart] | The content of the assistant message. |
| name | str | None | A name identifying the creator of this message. |
| provider | Provider | None | The LLM provider that generated this assistant message, if available. |
| model_id | ModelId | None | The model identifier of the LLM that generated this assistant message, if available. |
| raw_message | Jsonable | None | The provider-specific raw representation of this assistant message, if available. If raw_content is truthy, then it may be used for provider-specific behavior when resuming an LLM interaction that included this assistant message. For example, we can reuse the provider-specific raw encoding rather than re-encoding the message from it's Mirascope content representation. This may also take advantage of server-side provider context, e.g. identifiers of reasoning context tokens that the provider generated. If present, the content should be encoded as JSON-serializable data, and in a format that matches representation the provider expects representing the Mirascope data. This may involve e.g. converting Pydantic `BaseModel`s into plain dicts via `model_dump`. Raw content is not required, as the Mirascope content can also be used to generate a valid input to the provider (potentially without taking advantage of provider-specific reasoning caches, etc). In that case raw content should be left empty. |
Attribute Message
Type: TypeAlias
A message in an LLM interaction.
Messages have a role (system, user, or assistant) and content that is a sequence of content parts. The content can include text, images, audio, documents, and tool interactions.
For most use cases, prefer the convenience functions system(), user(), and
assistant() instead of directly creating Message objects.
Example:
from mirascope import llm
messages = [
llm.messages.system("You are a helpful assistant."),
llm.messages.user("Hello, how are you?"),
]Attribute SystemContent
Type: TypeAlias
Type alias for content that can fit into a SystemMessage.
Class SystemMessage
A system message that sets context and instructions for the conversation.
Attributes
| Name | Type | Description |
|---|---|---|
| role | Literal['system'] | The role of this message. Always "system". |
| content | Text | The content of this `SystemMesssage`. |
Attribute UserContent
Type: TypeAlias
Type alias for content that can fit into a UserMessage.
Class UserMessage
A user message containing input from the user.
Attributes
| Name | Type | Description |
|---|---|---|
| role | Literal['user'] | The role of this message. Always "user". |
| content | Sequence[UserContentPart] | The content of the user message. |
| name | str | None | A name identifying the creator of this message. |
Function assistant
Creates an assistant message.
Parameters
| Name | Type | Description |
|---|---|---|
| content | AssistantContent | The content of the message, which can be `str` or any `AssistantContent`, or a sequence of assistant content pieces. |
| provider | Provider | None | Optional identifier of the provider that produced this message. |
| model_id | ModelId | None | Optional id of the model that produced this message. |
| raw_message= None | Jsonable | None | Optional Jsonable object that contains the provider-specific "raw" data representation of the content for this assistant message. |
| name= None | str | None | Optional name to identify a specific assistant in multi-party conversations. |
Returns
| Type | Description |
|---|---|
| AssistantMessage | An `AssistantMessage`. |
Function system
Creates a system message.
Parameters
| Name | Type | Description |
|---|---|---|
| content | SystemContent | The content of the message, which must be a `str` or `Text` content. |
Returns
| Type | Description |
|---|---|
| SystemMessage | A `SystemMessage`. |
Function user
Creates a user message.
Parameters
| Name | Type | Description |
|---|---|---|
| content | UserContent | The content of the message, which can be `str` or any `UserContent`, or a sequence of such user content pieces. |
| name= None | str | None | Optional name to identify a specific user in multi-party conversations. |
Returns
| Type | Description |
|---|---|
| UserMessage | A `UserMessage`. |