Normalized message struct used across all LLM providers.
Represents a single message in a conversation, supporting system, user, assistant, and tool roles.
Summary
Functions
Applies fun to every attachment on every message, halting on the first error.
Creates a new message with validated attributes.
Types
Functions
@spec map_attachments([t()], (attachment() -> {:ok, attachment()} | {:error, error})) :: {:ok, [t()]} | {:error, error} when error: term()
Applies fun to every attachment on every message, halting on the first error.
Provider services use this to resolve attachments - loading bytes, uploading oversized files - before building a request body, so their formatting functions stay free of IO.
Creates a new message with validated attributes.
Examples
iex> {:ok, msg} = ExAgent.Message.new(role: :user, content: "Hello")
iex> msg.role
:user
iex> ExAgent.Message.new(role: :invalid, content: "Hello")
{:error, "invalid role: :invalid. Must be one of: [:system, :user, :assistant, :tool]"}
iex> ExAgent.Message.new(role: :user)
{:error, "content is required"}