Class: RCrewAI::HumanInput

Inherits:
Object
  • Object
show all
Defined in:
lib/rcrewai/human_input.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(**options)
  @session_id = options[:session_id] || generate_session_id
  @timeout = options.fetch(:timeout, 300) # 5 minutes default
  @logger = Logger.new($stdout)
  @logger.level = options.fetch(:verbose, false) ? Logger::DEBUG : Logger::INFO
  @interactions = []
  @input_history = []
  @auto_approve = options.fetch(:auto_approve, false) # For testing/automation
  @approval_keywords = options.fetch(:approval_keywords, %w[yes y approve ok continue])
  @rejection_keywords = options.fetch(:rejection_keywords, %w[no n reject cancel abort])
end

Instance Attribute Details

#interactionsObject (readonly)

Returns the value of attribute interactions.



9
10
11
# File 'lib/rcrewai/human_input.rb', line 9

def interactions
  @interactions
end

#loggerObject (readonly)

Returns the value of attribute logger.



9
10
11
# File 'lib/rcrewai/human_input.rb', line 9

def logger
  @logger
end

#session_idObject (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

#timeoutObject (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, **options)
  interaction = create_interaction(:confirmation, action_description, options)

  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, **options)
  interaction = create_interaction(:feedback, prompt, options)

  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(message, **options)
  interaction = create_interaction(:approval, message, options)

  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, **options)
  interaction = create_interaction(:choice, prompt, options.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, **options)
  interaction = create_interaction(:input, prompt, options)

  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, **options)
  interaction = create_interaction(:review, content, options)

  display_review_request(interaction)
  response = get_user_input(interaction)

  result = process_review_response(response, interaction)
  record_interaction(interaction, response, result)

  result
end

#session_summaryObject



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