Class: Protege::ModelMessage

Inherits:
Data
  • Object
show all
Defined in:
lib/protege/types/model_message.rb

Overview

One normalized message in a chat-completions conversation — a role plus its content (one or more content parts) and optional tool correlation. This is the pipeline-wide currency the model layer speaks: providers serialize it to the wire (+Inference::Provider::Request#to_wire+), the harness threads it through a run, and resolvers build it (via Resolver#message) to contribute context. It lives here at the top level beside the content parts it carries (+TextPart+ / ImagePart / DocumentPart) rather than inside Inference, because — like them — it is ownerless currency every layer constructs and reads, not any one layer's private type. (It cannot be Protege::Message: that name is the stored-email ActiveRecord model.)

role and content are always required. The tool-correlation fields are optional: tool_call_id is meaningful only when role is :tool (it correlates a tool result back to the call); tool_calls is meaningful only when role is :assistant and the model is requesting tool execution.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role:, content:, tool_call_id: nil, tool_calls: nil) ⇒ ModelMessage

Returns a new instance of ModelMessage.

Parameters:

  • role (Symbol)

    one of :system, :user, :assistant, :tool.

  • content (String, Array<TextPart>)

    message content; String for the text-only case.

  • tool_call_id (String, nil) (defaults to: nil)

    correlates a role: :tool message to its originating call.

  • tool_calls (Array<ToolCall>, nil) (defaults to: nil)

    tool calls the model requested (assistant only).



27
28
29
# File 'lib/protege/types/model_message.rb', line 27

def initialize(role:, content:, tool_call_id: nil, tool_calls: nil)
  super
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



17
18
19
# File 'lib/protege/types/model_message.rb', line 17

def content
  @content
end

#roleObject (readonly)

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



17
18
19
# File 'lib/protege/types/model_message.rb', line 17

def role
  @role
end

#tool_call_idObject (readonly)

Returns the value of attribute tool_call_id

Returns:

  • (Object)

    the current value of tool_call_id



17
18
19
# File 'lib/protege/types/model_message.rb', line 17

def tool_call_id
  @tool_call_id
end

#tool_callsObject (readonly)

Returns the value of attribute tool_calls

Returns:

  • (Object)

    the current value of tool_calls



17
18
19
# File 'lib/protege/types/model_message.rb', line 17

def tool_calls
  @tool_calls
end

Instance Method Details

#partsArray<TextPart>

Return content as a normalized parts array.

Array content passes through unchanged; String content is wrapped in a single TextPart.

Returns:

  • (Array<TextPart>)

    the content normalized to parts.



36
37
38
# File 'lib/protege/types/model_message.rb', line 36

def parts
  content.is_a?(Array) ? content : [TextPart.new(text: content)]
end