Message

org.llm4s.llmconnect.model.Message
See theMessage companion trait
object Message

Companion object providing smart constructors and conversation-level validation.

The smart constructors (system, user, assistant, tool) return Left(ValidationError) on blank content so callers get typed errors instead of runtime exceptions. Prefer these over the case-class constructors in application code; use case-class constructors directly only in tests or when content is guaranteed non-blank.

Attributes

Companion
trait
Graph
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Message.type

Members list

Type members

Inherited and Abstract types

type MirroredElemLabels <: Tuple

The names of the product elements

The names of the product elements

Attributes

Inherited from:
Mirror
type MirroredLabel <: String

The name of the type

The name of the type

Attributes

Inherited from:
Mirror

Value members

Concrete methods

def assistant(content: String, toolCalls: List[ToolCall]): Result[AssistantMessage]
def system(content: String): Result[SystemMessage]
def tool(content: String, toolCallId: String): Result[ToolMessage]
def user(content: String): Result[UserMessage]
def validateConversation(messages: List[Message]): Result[Unit]

Validates structural consistency of a full conversation.

Validates structural consistency of a full conversation.

Three checks are applied in order and all failures are collected before returning, so callers see every problem in a single pass:

  1. Each message satisfies its individual Message.validate constraint.
  2. Conversation-flow rules: system messages only at the start; tool messages must be preceded by an assistant message that requested the matching tool call.
  3. Tool-call/response pairing: every tool call in an assistant message must have exactly one ToolMessage response with a matching toolCallId, and vice-versa.

An empty messages list is considered valid.

Value parameters

messages

Messages in conversation order (oldest first).

Attributes

Returns

Right(()) when all checks pass; Left(ValidationError) with all violations listed in error.violations when any check fails.

Implicits

Implicits

implicit val rw: ReadWriter[Message]