Class: Collavre::Orchestration::Arbiter

Inherits:
Object
  • Object
show all
Defined in:
app/services/collavre/orchestration/arbiter.rb

Overview

Arbiter decides which agents will actually respond from the qualified candidates. This implements “floor control” - preventing multiple agents from responding simultaneously.

Strategies:

  • all: All candidates respond (original behavior)

  • primary_first: Primary agent responds, others only if primary unavailable

  • round_robin: Rotate between agents for each message

  • bid: Select agent based on relevance score (expertise matching)

Constant Summary collapse

DEFAULT_CONFIDENCE_THRESHOLD =

Default confidence threshold for bid strategy

0.3

Instance Method Summary collapse

Constructor Details

#initialize(context, policy_resolver: nil) ⇒ Arbiter

Returns a new instance of Arbiter.



17
18
19
20
# File 'app/services/collavre/orchestration/arbiter.rb', line 17

def initialize(context, policy_resolver: nil)
  @context = context
  @policy_resolver = policy_resolver || PolicyResolver.new(context)
end

Instance Method Details

#select(candidates) ⇒ Array<User>

Select which agents will respond from the candidates

Parameters:

  • candidates (Array<User>)

    Qualified agents from Matcher

Returns:

  • (Array<User>)

    Agents that will actually respond



25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/services/collavre/orchestration/arbiter.rb', line 25

def select(candidates)
  return [] if candidates.empty?

  strategy = @policy_resolver.arbitration_strategy
  selected = apply_strategy(strategy, candidates)

  # Apply max_responders limit if set
  max = @policy_resolver.max_responders
  selected = selected.take(max) if max.present? && max.positive?

  selected
end