Class: Protege::Inference::Provider::Request

Inherits:
Data
  • Object
show all
Defined in:
lib/protege/inference/provider/request.rb

Overview

One normalized generation request handed to a provider's #generate method — the conversation only: the ordered messages plus the tool schemas to expose. Model, sampling, and credentials are not carried here; each provider reads those from its own config.providers slice.

messages is the complete ordered message array for this generation call — resolver context messages (role: :system, :user, :assistant) prepended by the harness, followed by the current inbound as a :user message. Providers handle role: :system messages according to their API requirements (OpenRouter normalises for all underlying models; a direct Anthropic provider would extract system messages into its top-level system: parameter).

Wire serialization

#to_wire renders the request into the standard (OpenAI-compatible) { messages:, tools: } body. This lives here — not on each provider — because it is the same serialization the API call needs and a trace needs: OpenRouterProvider#generate builds its payload by merging model/sampling onto to_wire, and the tracing subscriber snapshots to_wire directly. Keeping it in one place means a trace records the exact conversation that was sent, never a re-derivation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messages:, tools: []) ⇒ Request

Returns a new instance of Request.

Parameters:

  • messages (Array<Protege::ModelMessage>)

    the ordered message array for this generation call

  • tools (Array<Protege::Inference::Tool>) (defaults to: [])

    the tools available to the model (default empty)



32
33
34
# File 'lib/protege/inference/provider/request.rb', line 32

def initialize(messages:, tools: [])
  super
end

Instance Attribute Details

#messagesObject (readonly)

Returns the value of attribute messages

Returns:

  • (Object)

    the current value of messages



26
27
28
# File 'lib/protege/inference/provider/request.rb', line 26

def messages
  @messages
end

#toolsObject (readonly)

Returns the value of attribute tools

Returns:

  • (Object)

    the current value of tools



26
27
28
# File 'lib/protege/inference/provider/request.rb', line 26

def tools
  @tools
end

Instance Method Details

#to_wireHash

Render this request as the standard chat-completions body: the serialized message array and the function-tool schemas. Model, sampling, and credentials are the provider's to add.

Returns:

  • (Hash)

    { messages: Array<Hash>, tools: Array<Hash> } (tools omitted when none)



40
41
42
43
44
45
# File 'lib/protege/inference/provider/request.rb', line 40

def to_wire
  {
    messages: messages.map { |message| wire_message(message) },
    tools:    tools.presence&.map { |tool| wire_tool(tool) }
  }.compact
end