ExAgent.Message (ExAgent v0.2.0)

Copy Markdown View Source

Normalized message struct used across all LLM providers.

Represents a single message in a conversation, supporting system, user, assistant, and tool roles.

Summary

Functions

Creates a new message with validated attributes.

Types

attachment()

@type attachment() ::
  %{data: binary(), mime_type: String.t()} | %{file_ref: ExAgent.FileRef.t()}

role()

@type role() :: :system | :user | :assistant | :tool

t()

@type t() :: %ExAgent.Message{
  attachments: [attachment()],
  content: String.t(),
  metadata: map(),
  role: role(),
  tool_call_id: String.t() | nil,
  tool_calls: [map()] | nil
}

Functions

new(attrs)

@spec new(keyword()) :: {:ok, t()} | {:error, String.t()}

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"}