Represents a message in the conversation history.
Messages can be from the user, the assistant, or represent tool results. Assistant messages may include tool calls and their results.
Message Roles
:user- A message from the user:assistant- A response from the LLM:tool_result- The result of a tool execution
Content Blocks
Assistant messages can contain multiple content blocks:
{:text, string}- Plain text{:thinking, string}- Model's reasoning (if thinking enabled){:tool_call, id, name, args}- A tool invocation
Summary
Functions
Creates a new assistant message.
Checks if the message contains any tool calls.
Extracts plain text from a message's content.
Extracts thinking content from a message.
Extracts tool calls from a message.
Creates a tool result message.
Extracts the content from a tool result message for display.
Creates a new user message.
Functions
Creates a new assistant message.
Content can be a string or a list of content blocks.
Checks if the message contains any tool calls.
Extracts plain text from a message's content.
Returns the concatenated text blocks for assistant messages, or the content directly for user messages.
Extracts thinking content from a message.
Extracts tool calls from a message.
Returns a list of {id, name, args} tuples.
Creates a tool result message.
The content will be JSON-encoded if not a string.
Extracts the content from a tool result message for display.
Creates a new user message.
Examples
Message.user("Hello!")
Message.user("What's in this image?", [%{type: :base64, media_type: "image/png", data: "..."}])