Class: Phronomy::MultiAgent::TeamCoordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/phronomy/multi_agent/team_coordinator.rb

Overview

Coordinator/worker multi-agent pattern with persistent worker Agent state.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

._aggregatorObject



59
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 59

def _aggregator = @aggregator

._coordinator_instructionsObject



53
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 53

def _coordinator_instructions = @coordinator_instructions

._coordinator_modelObject



52
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 52

def _coordinator_model = @coordinator_model

._coordinator_providerObject



54
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 54

def _coordinator_provider = @coordinator_provider

._on_errorObject



57
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 57

def _on_error = @on_error || :raise

._pool_sizeObject



55
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 55

def _pool_size = @pool_size || 1

._schedulerObject



58
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 58

def _scheduler = @scheduler

._worker_agentObject



56
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 56

def _worker_agent = @worker_agent

.aggregate(&block) ⇒ Object



48
49
50
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 48

def aggregate(&block)
  @aggregator = block
end

.coordinator_instructions(value = nil) ⇒ Object



26
27
28
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 26

def coordinator_instructions(value = nil)
  value ? @coordinator_instructions = value : @coordinator_instructions
end

.coordinator_model(value = nil) ⇒ Object



21
22
23
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 21

def coordinator_model(value = nil)
  value ? @coordinator_model = value : @coordinator_model
end

.coordinator_provider(value = nil) ⇒ Object



31
32
33
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 31

def coordinator_provider(value = nil)
  value ? @coordinator_provider = value : @coordinator_provider
end

.pool(size:, agent:, on_error: :raise) ⇒ Object



36
37
38
39
40
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 36

def pool(size:, agent:, on_error: :raise)
  @pool_size = Integer(size)
  @worker_agent = agent
  @on_error = on_error
end

.schedule(&block) ⇒ Object



43
44
45
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 43

def schedule(&block)
  @scheduler = block
end

Instance Method Details

#invoke(team_input, config: {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 63

def invoke(team_input, config: {})
  unless self.class._worker_agent
    raise ArgumentError, "pool :agent must be configured before invoking"
  end

  task_queue = []
  run_coordinator(team_input, task_queue)
  assignments = run_workers(task_queue)
  finalize_result(assignments)
end

#stream(team_input, config: {}, &block) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/phronomy/multi_agent/team_coordinator.rb', line 75

def stream(team_input, config: {}, &block)
  return invoke(team_input, config: config) unless block

  unless self.class._worker_agent
    raise ArgumentError, "pool :agent must be configured before invoking"
  end

  task_queue = []
  run_coordinator(team_input, task_queue)
  assignments = run_workers(task_queue, &block)
  finalize_result(assignments)
end