Module: LLM::Backend

Defined in:
lib/scout/llm/backends/default.rb

Overview

Shared implementation for all LLM backends.

This file used to expose its API by doing ‘extend Backend` in each backend module. That worked for simple overrides, but other backends (notably OpenWebUI) started copying singleton methods from another backend. Copying/binding singleton methods breaks Ruby’s internal dispatch because internal calls stay bound to the original receiver.

The supported/idiomatic way to share backend logic while allowing overrides is to keep the shared implementation as a module, and compose backends by building their singleton-method lookup chain:

class << self
  prepend BackendSpecificMethods   # overrides
  include Backend::ClassMethods    # shared implementation
end

With this arrangement, shared methods (like ‘ask`) can call overridable methods (like `query` / `format_tool_call`) and Ruby will correctly dispatch to the backend override.

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object

Backwards-compatibility with the old pattern (‘extend Backend`).

We now recommend composing backends by manipulating their singleton class directly, but keeping these hooks makes the transition incremental.



593
594
595
# File 'lib/scout/llm/backends/default.rb', line 593

def self.extended(base)
  base.singleton_class.include(ClassMethods)
end

.included(base) ⇒ Object



597
598
599
# File 'lib/scout/llm/backends/default.rb', line 597

def self.included(base)
  base.extend(ClassMethods)
end