Class: Insika::ModelResolver
- Inherits:
-
Object
- Object
- Insika::ModelResolver
- Defined in:
- lib/insika/model_resolver.rb
Overview
LLM config v2 resolution (FOLLOWUP §10). Turns the three config layers into a single ModelSelection at turn start:
Chat (per-session pin) > Agent (profile.model) > Platform default (Settings)
Also enforces the agent's model_policy on the RESOLVED model (a chat pin can
never escape the fence) and resolves the fallback chain + selection source.
Pure: no ruby_llm, no store writes. settings_store is optional — nil means
"no platform layer" (an agent WITHOUT a model then fails high), preserving the
pre-v2 behavior for the many call sites that build an Executor without one.
Constant Summary collapse
- SESSION_SLOT =
Reserved, collision-safe slot for the per-session model pin inside
session.vars(namespaced so it never renders in <request_context> — the Request provider skips "__"-prefixed vars). "__llm__"
Instance Method Summary collapse
-
#initialize(settings_store: nil) ⇒ ModelResolver
constructor
A new instance of ModelResolver.
-
#resolve(profile:, session: nil) ⇒ Object
profile: AgentProfile; session: SessionStore::Session | nil.
Constructor Details
#initialize(settings_store: nil) ⇒ ModelResolver
Returns a new instance of ModelResolver.
21 22 23 |
# File 'lib/insika/model_resolver.rb', line 21 def initialize(settings_store: nil) @settings_store = settings_store end |
Instance Method Details
#resolve(profile:, session: nil) ⇒ Object
profile: AgentProfile; session: SessionStore::Session | nil. -> ModelSelection. Raises PolicyDenied (model outside the agent's fence) or Error (no model resolvable at any layer).
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/insika/model_resolver.rb', line 33 def resolve(profile:, session: nil) settings = platform_settings choice = pick(profile, session, settings) if blank?(choice.model) raise Insika::Error, "no model resolved for agent '#{profile.id}': set the agent model or a platform default_model (Settings)" end provider = choice.provider&.to_sym enforce_policy!(profile, choice.model, provider) ModelSelection.new( model: choice.model, provider: provider, source: choice.source, pinned: choice.pinned, params: resolve_params(profile, session, settings, choice.model, provider), fallbacks: choice.pinned ? [] : resolve_fallbacks(profile, settings, choice.model, provider) ) end |