Class: Legion::Extensions::Agentic::Self::SelfTalk::Helpers::Dialogue
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Self::SelfTalk::Helpers::Dialogue
- Defined in:
- lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb
Instance Attribute Summary collapse
-
#conclusion ⇒ Object
readonly
Returns the value of attribute conclusion.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
-
#turns ⇒ Object
readonly
Returns the value of attribute turns.
Instance Method Summary collapse
- #abandon! ⇒ Object
- #active? ⇒ Boolean
- #add_turn!(voice_id:, content:, position: :clarify, strength: 0.5) ⇒ Object
- #conclude!(summary) ⇒ Object
- #concluded? ⇒ Boolean
- #consensus_label ⇒ Object
- #consensus_score ⇒ Object
- #deadlock! ⇒ Object
-
#initialize(topic:) ⇒ Dialogue
constructor
A new instance of Dialogue.
- #to_h ⇒ Object
- #turn_count ⇒ Object
- #voice_positions ⇒ Object
Constructor Details
#initialize(topic:) ⇒ Dialogue
Returns a new instance of Dialogue.
14 15 16 17 18 19 20 21 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 14 def initialize(topic:) @id = SecureRandom.uuid @topic = topic @turns = [] @status = :open @conclusion = nil @created_at = Time.now.utc end |
Instance Attribute Details
#conclusion ⇒ Object (readonly)
Returns the value of attribute conclusion.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 12 def conclusion @conclusion end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 12 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 12 def id @id end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 12 def status @status end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 12 def topic @topic end |
#turns ⇒ Object (readonly)
Returns the value of attribute turns.
12 13 14 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 12 def turns @turns end |
Instance Method Details
#abandon! ⇒ Object
53 54 55 56 57 58 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 53 def abandon! return false unless active? @status = :abandoned true end |
#active? ⇒ Boolean
60 61 62 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 60 def active? @status == :open end |
#add_turn!(voice_id:, content:, position: :clarify, strength: 0.5) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 23 def add_turn!(voice_id:, content:, position: :clarify, strength: 0.5) return false if @turns.size >= Constants::MAX_TURNS_PER_DIALOGUE return false unless active? turn = DialogueTurn.new( dialogue_id: @id, voice_id: voice_id, content: content, position: position, strength: strength ) @turns << turn turn end |
#conclude!(summary) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 38 def conclude!(summary) return false unless active? @conclusion = summary @status = :concluded true end |
#concluded? ⇒ Boolean
64 65 66 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 64 def concluded? @status == :concluded end |
#consensus_label ⇒ Object
91 92 93 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 91 def consensus_label Constants.consensus_label(consensus_score) end |
#consensus_score ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 79 def consensus_score return 1.0 if @turns.empty? support_strength = @turns.select { |t| t.position == :support }.sum(&:strength) oppose_strength = @turns.select { |t| t.position == :oppose }.sum(&:strength) total = support_strength + oppose_strength return 0.5 if total.zero? stronger = [support_strength, oppose_strength].max stronger / total end |
#deadlock! ⇒ Object
46 47 48 49 50 51 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 46 def deadlock! return false unless active? @status = :deadlocked true end |
#to_h ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 95 def to_h { id: @id, topic: @topic, status: @status, conclusion: @conclusion, turn_count: turn_count, consensus_score: consensus_score.round(10), consensus_label: consensus_label, created_at: @created_at, turns: @turns.map(&:to_h) } end |
#turn_count ⇒ Object
68 69 70 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 68 def turn_count @turns.size end |
#voice_positions ⇒ Object
72 73 74 75 76 77 |
# File 'lib/legion/extensions/agentic/self/self_talk/helpers/dialogue.rb', line 72 def voice_positions grouped = @turns.group_by(&:voice_id) grouped.transform_values do |voice_turns| voice_turns.sum(&:strength) / voice_turns.size.to_f end end |