Class: RCrewAI::HumanInput
- Inherits:
-
Object
- Object
- RCrewAI::HumanInput
- Defined in:
- lib/rcrewai/human_input.rb
Instance Attribute Summary collapse
-
#interactions ⇒ Object
readonly
Returns the value of attribute interactions.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
- #confirm_action(action_description, **options) ⇒ Object
- #get_feedback(prompt, **options) ⇒ Object
-
#initialize(**options) ⇒ HumanInput
constructor
A new instance of HumanInput.
- #request_approval(message, **options) ⇒ Object
- #request_choice(prompt, choices, **options) ⇒ Object
- #request_input(prompt, **options) ⇒ Object
- #request_review(content, **options) ⇒ Object
- #session_summary ⇒ Object
Constructor Details
#initialize(**options) ⇒ HumanInput
Returns a new instance of HumanInput.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rcrewai/human_input.rb', line 11 def initialize(**) @session_id = [:session_id] || generate_session_id @timeout = .fetch(:timeout, 300) # 5 minutes default @logger = Logger.new($stdout) @logger.level = .fetch(:verbose, false) ? Logger::DEBUG : Logger::INFO @interactions = [] @input_history = [] @auto_approve = .fetch(:auto_approve, false) # For testing/automation @approval_keywords = .fetch(:approval_keywords, %w[yes y approve ok continue]) @rejection_keywords = .fetch(:rejection_keywords, %w[no n reject cancel abort]) end |
Instance Attribute Details
#interactions ⇒ Object (readonly)
Returns the value of attribute interactions.
9 10 11 |
# File 'lib/rcrewai/human_input.rb', line 9 def interactions @interactions end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
9 10 11 |
# File 'lib/rcrewai/human_input.rb', line 9 def logger @logger end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
9 10 11 |
# File 'lib/rcrewai/human_input.rb', line 9 def session_id @session_id end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/rcrewai/human_input.rb', line 9 def timeout @timeout end |
Instance Method Details
#confirm_action(action_description, **options) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rcrewai/human_input.rb', line 73 def confirm_action(action_description, **) interaction = create_interaction(:confirmation, action_description, ) return handle_auto_approval(interaction) if @auto_approve display_confirmation_request(interaction) response = get_user_input(interaction) result = process_confirmation_response(response, interaction) record_interaction(interaction, response, result) result end |
#get_feedback(prompt, **options) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rcrewai/human_input.rb', line 87 def get_feedback(prompt, **) interaction = create_interaction(:feedback, prompt, ) display_feedback_request(interaction) response = get_user_input(interaction) result = { feedback: response, timestamp: Time.now } record_interaction(interaction, response, result) result end |
#request_approval(message, **options) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rcrewai/human_input.rb', line 23 def request_approval(, **) interaction = create_interaction(:approval, , ) return handle_auto_approval(interaction) if @auto_approve display_approval_request(interaction) response = get_user_input(interaction) result = process_approval_response(response, interaction) record_interaction(interaction, response, result) result end |
#request_choice(prompt, choices, **options) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rcrewai/human_input.rb', line 49 def request_choice(prompt, choices, **) interaction = create_interaction(:choice, prompt, .merge(choices: choices)) display_choice_request(interaction) response = get_user_input(interaction) result = process_choice_response(response, interaction) record_interaction(interaction, response, result) result end |
#request_input(prompt, **options) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rcrewai/human_input.rb', line 37 def request_input(prompt, **) interaction = create_interaction(:input, prompt, ) display_input_request(interaction) response = get_user_input(interaction) result = process_input_response(response, interaction) record_interaction(interaction, response, result) result end |
#request_review(content, **options) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rcrewai/human_input.rb', line 61 def request_review(content, **) interaction = create_interaction(:review, content, ) display_review_request(interaction) response = get_user_input(interaction) result = process_review_response(response, interaction) record_interaction(interaction, response, result) result end |
#session_summary ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rcrewai/human_input.rb', line 99 def session_summary { session_id: @session_id, total_interactions: @interactions.length, interaction_types: @interactions.group_by { |i| i[:type] }.transform_values(&:count), approvals: @interactions.count { |i| i[:result]&.dig(:approved) }, rejections: @interactions.count { |i| i[:result]&.dig(:approved) == false }, duration: calculate_session_duration, first_interaction: @interactions.first&.dig(:timestamp), last_interaction: @interactions.last&.dig(:timestamp) } end |