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.
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:
Each message satisfies its individual Message.validate constraint.
Conversation-flow rules: system messages only at the start; tool messages must be preceded by an assistant message that requested the matching tool call.
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.