Mirascopev2
Lilypad

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

NameTypeDescription
roleLiteral['assistant']The role of this message. Always "assistant".
contentSequence[AssistantContentPart]The content of the assistant message.
namestr | NoneA name identifying the creator of this message.
providerProvider | NoneThe LLM provider that generated this assistant message, if available.
model_idModelId | NoneThe model identifier of the LLM that generated this assistant message, if available.
raw_messageJsonable | NoneThe 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

NameTypeDescription
roleLiteral['system']The role of this message. Always "system".
contentTextThe 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

NameTypeDescription
roleLiteral['user']The role of this message. Always "user".
contentSequence[UserContentPart]The content of the user message.
namestr | NoneA name identifying the creator of this message.

Function assistant

Creates an assistant message.

Parameters

NameTypeDescription
contentAssistantContentThe content of the message, which can be `str` or any `AssistantContent`, or a sequence of assistant content pieces.
providerProvider | NoneOptional identifier of the provider that produced this message.
model_idModelId | NoneOptional id of the model that produced this message.
raw_message= NoneJsonable | NoneOptional Jsonable object that contains the provider-specific "raw" data representation of the content for this assistant message.
name= Nonestr | NoneOptional name to identify a specific assistant in multi-party conversations.

Returns

TypeDescription
AssistantMessageAn `AssistantMessage`.

Function system

Creates a system message.

Parameters

NameTypeDescription
contentSystemContentThe content of the message, which must be a `str` or `Text` content.

Returns

TypeDescription
SystemMessageA `SystemMessage`.

Function user

Creates a user message.

Parameters

NameTypeDescription
contentUserContentThe content of the message, which can be `str` or any `UserContent`, or a sequence of such user content pieces.
name= Nonestr | NoneOptional name to identify a specific user in multi-party conversations.

Returns

TypeDescription
UserMessageA `UserMessage`.