Module: Legion::LLM::Router::RequiredCapabilities

Extended by:
Legion::Logging::Helper
Includes:
Legion::Logging::Helper
Defined in:
lib/legion/llm/router/required_capabilities.rb

Overview

Sole request-shape-to-capability derivation (SSOT v3 §9.2).

This is the ONLY place that maps a canonical Inference::Request to a set of routing capability requirements. No route handler, translator, payload builder, executor step, embedding helper, or provider adapter independently derives routing capabilities.

The HTTP dialect that produced the request (OpenAI, Anthropic, native) is invisible here. In particular, the OpenAI Responses dialect DOES NOT add a :responses capability — canonical chat/stream_chat operations flow through ordinary operation evidence.

See Also:

  • for the CANONICAL list and normalize/alias rules.

Constant Summary collapse

OPERATION_BASE =

Base capabilities required by each operation, independent of request shape.

{
  chat:         [].freeze,
  stream_chat:  %i[streaming].freeze,
  embed:        %i[embedding].freeze,
  image:        %i[image].freeze,
  transcribe:   %i[audio_transcription].freeze,
  translate:    [].freeze,
  speak:        %i[audio_speech].freeze,
  moderate:     %i[moderation].freeze,
  count_tokens: [].freeze
}.freeze

Class Method Summary collapse

Class Method Details

.call(request:, operation:) ⇒ Array<Symbol>

Derive the complete frozen capability requirement set for a canonical request.

Parameters:

  • request (Legion::LLM::Inference::Request)

    canonical request Data object; fields are read defensively — nil/missing fields are treated as the requirement not being triggered.

  • operation (Symbol)

    one of the Phase 1 Taxonomies::OPERATIONS values

Returns:

  • (Array<Symbol>)

    frozen, normalized, deduplicated canonical capability Symbols



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/legion/llm/router/required_capabilities.rb', line 43

def call(request:, operation:)
  caps = OPERATION_BASE.fetch(operation, []).dup

  caps << :tools             if tools_required?(request)
  caps << :thinking          if thinking_required?(request)
  caps << :vision            if vision_required?(request)
  caps << :structured_output if structured_output_required?(request)

  result = Legion::Extensions::Llm::Capabilities.normalize(caps)
  log.debug("[llm][required_capabilities] action=derive operation=#{operation} caps=#{result.inspect}")
  result
end