Class: Insika::ModelSelection

Inherits:
Data
  • Object
show all
Defined in:
lib/insika/model_selection.rb

Overview

The RESOLVED model decision for a turn (ModelResolver output). Immutable snapshot carried on the TurnState, applied to the RubyLLM chat at stage 5 and surfaced in the turn's usage for telemetry/billing.

Fields:

model     -> the resolved model id (String) | nil (RubyLLM's own default)
provider  -> Symbol | nil (nil => RubyLLM infers from the model registry)
source    -> :chat | :agent | :platform_default (WHERE the model came from)
pinned    -> true when the model is a USER pin (per-chat override). A pin
           "fails HIGH": no silent fallback (OpenClaw semantics). An agent
           model / platform default is NOT pinned -> fallbacks apply.
params    -> generation params (Hash of symbols: temperature/max_tokens/thinking)
fallbacks -> ordered [{ model:, provider: }] to try when NOT pinned. The
           mid-turn ROTATION across this chain (plus the profile's own
           reliability["fallback"] refs) is WS3's Reliability coordinator;
           here the chain is resolved + surfaced (source/pinned) for it.

Constant Summary collapse

THINKING_LEVELS =

The selectable reasoning values (4-layer). Blank/absent = inherit the broader layer; these are the explicit choices. Shared with the Studio forms. Defined on the class OUTSIDE the Data.define block on purpose: a constant assigned inside the block would land in the enclosing lexical scope (Insika), not on ModelSelection.

%w[off on low medium high].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, provider: nil, source: :platform_default, pinned: false, params: {}, fallbacks: []) ⇒ ModelSelection

Returns a new instance of ModelSelection.



21
22
23
24
# File 'lib/insika/model_selection.rb', line 21

def initialize(model:, provider: nil, source: :platform_default, pinned: false,
               params: {}, fallbacks: [])
  super
end

Instance Attribute Details

#fallbacksObject (readonly)

Returns the value of attribute fallbacks

Returns:

  • (Object)

    the current value of fallbacks



20
21
22
# File 'lib/insika/model_selection.rb', line 20

def fallbacks
  @fallbacks
end

#modelObject (readonly)

Returns the value of attribute model

Returns:

  • (Object)

    the current value of model



20
21
22
# File 'lib/insika/model_selection.rb', line 20

def model
  @model
end

#paramsObject (readonly)

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



20
21
22
# File 'lib/insika/model_selection.rb', line 20

def params
  @params
end

#pinnedObject (readonly)

Returns the value of attribute pinned

Returns:

  • (Object)

    the current value of pinned



20
21
22
# File 'lib/insika/model_selection.rb', line 20

def pinned
  @pinned
end

#providerObject (readonly)

Returns the value of attribute provider

Returns:

  • (Object)

    the current value of provider



20
21
22
# File 'lib/insika/model_selection.rb', line 20

def provider
  @provider
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



20
21
22
# File 'lib/insika/model_selection.rb', line 20

def source
  @source
end

Instance Method Details

#apply_params(chat) ⇒ Object

Applies the generation params to a RubyLLM chat (or any object exposing the same with_* fluent API). Pure and duck-typed: a with_* the target does not expose is skipped (a fake chat in specs need only implement the ones it asserts). RubyLLM raises on a nil arg, so only PRESENT params are applied. Returns the chat (the with_* calls mutate and return self).



37
38
39
40
41
42
43
# File 'lib/insika/model_selection.rb', line 37

def apply_params(chat)
  p = params || {}
  apply(chat, :with_temperature, p[:temperature]) if numeric?(p[:temperature])
  apply_payload_params(chat, p)
  apply_effort(chat, p[:thinking]) if present?(p[:thinking])
  chat
end

#assume_model_exists?Boolean

provider present => tell RubyLLM to trust the id (skip the registry lookup), matching the pre-v2 create_chat behavior.

Returns:

  • (Boolean)


30
# File 'lib/insika/model_selection.rb', line 30

def assume_model_exists? = !provider.nil?

#pinned?Boolean

Returns:

  • (Boolean)


26
# File 'lib/insika/model_selection.rb', line 26

def pinned? = pinned