Class: AIA::DelegateHandler
- Inherits:
-
Object
- Object
- AIA::DelegateHandler
- Includes:
- ContentExtractor, HandlerProtocol
- Defined in:
- lib/aia/delegate_handler.rb
Instance Attribute Summary collapse
-
#robot ⇒ Object
writeonly
Sets the attribute robot.
Instance Method Summary collapse
-
#handle(context) ⇒ String?
Decompose a prompt into subtasks, assign to robots, and execute.
-
#initialize(robot:, ui_presenter:, tracker:, task_coordinator:) ⇒ DelegateHandler
constructor
A new instance of DelegateHandler.
Methods included from ContentExtractor
#extract_content, #extract_network_content, #format_duration, #output_to_file, #present_result, #store_results_in_memory
Constructor Details
#initialize(robot:, ui_presenter:, tracker:, task_coordinator:) ⇒ DelegateHandler
Returns a new instance of DelegateHandler.
17 18 19 20 21 22 |
# File 'lib/aia/delegate_handler.rb', line 17 def initialize(robot:, ui_presenter:, tracker:, task_coordinator:) @robot = robot @ui_presenter = ui_presenter @tracker = tracker @task_coordinator = task_coordinator end |
Instance Attribute Details
#robot=(value) ⇒ Object (writeonly)
Sets the attribute robot
24 25 26 |
# File 'lib/aia/delegate_handler.rb', line 24 def robot=(value) @robot = value end |
Instance Method Details
#handle(context) ⇒ String?
Decompose a prompt into subtasks, assign to robots, and execute.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/aia/delegate_handler.rb', line 30 def handle(context) prompt = context.prompt return nil unless @robot.network? return nil unless @task_coordinator&.available? robots = @robot.robots robot_names = robots.values.map(&:name) lead = robots.values.first # Step 1: Decompose the work decomposer = TaskDecomposer.new(lead_robot: lead, ui_presenter: @ui_presenter) steps = decomposer.decompose(prompt, robot_names) if steps.empty? @ui_presenter.display_info("Could not decompose into subtasks.") return nil end # Step 2: Create TrakFlow plan plan = @task_coordinator.create_plan( "Delegated: #{prompt[0, 60]}", steps: steps, creator: lead.name, ephemeral: true ) @ui_presenter.display_info("Plan with #{steps.size} tasks:") steps.each_with_index do |s, i| @ui_presenter.display_info(" #{i + 1}. #{s[:title]} -> #{s[:assignee]}") end # Step 3: Execute tasks in order executor = TaskExecutor.new(task_coordinator: @task_coordinator) results = execute_steps(executor, prompt, plan, steps, robots) @tracker.record_turn( model: AIA.config.models.first.name, input: prompt, result: results ) format_results(results) end |