Module: Legion::LLM::Call::SelectionDispatch

Extended by:
Legion::Logging::Helper
Defined in:
lib/legion/llm/call/selection_dispatch.rb

Overview

Exact local dispatch (SSOT v3 ยง15.1). Acquires the exact callable handle named by a Selection (never re-resolves by provider/model), invokes the operation-specific callable method, normalizes a provider StandardError into a Phase 1 ProviderOutcome via that exact callable's normalize_dispatch_error, and always releases the owned DispatchLease in ensure. It never rescues a typed routing/provider outcome into a success-shaped Hash.

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Class Method Details

.call(attempt_context:, arguments:, dispatch_lease: nil, &block) ⇒ Object

Protected operation args removed before passthrough, per operation. Argument validation and protected-key extraction (programming errors) happen BEFORE handle acquisition and the provider-error rescue, so an ArgumentError never becomes a normalized provider failure.

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/legion/llm/call/selection_dispatch.rb', line 50

def self.call(attempt_context:, arguments:, dispatch_lease: nil, &block)
  raise ArgumentError, 'arguments must be a Hash' unless arguments.is_a?(Hash)

  selection = attempt_context.selection
  invocation = plan_invocation(operation: selection.operation, model: selection.model,
                               arguments: arguments, block: block)

  owned_lease = dispatch_lease.nil?
  lease = dispatch_lease || Legion::Extensions::Llm::Inventory::Registry.acquire(
    callable_handle: selection.callable_handle
  )
  callable = lease.callable

  begin
    Result.success(value: invocation.call(callable))
  rescue StandardError => e
    Result.failure(outcome: normalize(callable: callable, error: e))
  ensure
    lease.release if owned_lease && !lease.released?
  end
end