Class: RobotLab::A2A::AskUserTool

Inherits:
Tool
  • Object
show all
Defined in:
lib/robot_lab/a2a/ask_user_tool.rb

Overview

Drop-in replacement for RobotLab::AskUser when a robot runs under A2A.

Instead of blocking a terminal, it pushes an input_required event through the event_queue so the RobotAdapter can call task.require_input! and emit_status(final: true), then blocks on answer_queue until the A2A client resumes the task with another message.

Inject before robot.run() via RobotAdapter — do not use directly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#answer_queue=(value) ⇒ Object (writeonly)

Sets the attribute answer_queue

Parameters:

  • value

    the value to set the attribute answer_queue to.



19
20
21
# File 'lib/robot_lab/a2a/ask_user_tool.rb', line 19

def answer_queue=(value)
  @answer_queue = value
end

#event_queue=(value) ⇒ Object (writeonly)

Sets the attribute event_queue

Parameters:

  • value

    the value to set the attribute event_queue to.



19
20
21
# File 'lib/robot_lab/a2a/ask_user_tool.rb', line 19

def event_queue=(value)
  @event_queue = value
end

Instance Method Details

#execute(question:, choices: nil, default: nil) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/robot_lab/a2a/ask_user_tool.rb', line 21

def execute(question:, choices: nil, default: nil)
  raise 'A2A queues not injected — use RobotLab::A2A::RobotAdapter' unless @event_queue

  prompt_text = format_prompt(question, choices, default)
  prompt      = ::A2A::Models::Message.agent(prompt_text)
  @event_queue.push({ type: :ask, prompt: prompt })

  answer = @answer_queue.pop
  answer = default if (answer.nil? || answer.strip.empty?) && default
  answer.to_s
end