Class: Legion::Extensions::Agentic::Language::InnerSpeech::Helpers::Utterance

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb

Constant Summary

Constants included from Constants

Constants::AUTOMATIC_SPEED, Constants::CONDENSATION_RATIO, Constants::CONTROLLED_SPEED, Constants::EGOCENTRIC_SPEED, Constants::MAX_HISTORY, Constants::MAX_STREAM_LENGTH, Constants::MAX_UTTERANCES, Constants::RUMINATION_THRESHOLD, Constants::SALIENCE_DECAY, Constants::SALIENCE_FLOOR, Constants::SPEECH_MODES, Constants::URGENCY_LABELS, Constants::VOICE_TYPES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, content:, mode: :narrating, **opts) ⇒ Utterance

Returns a new instance of Utterance.



15
16
17
18
19
20
21
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 15

def initialize(id:, content:, mode: :narrating, **opts)
  @id               = id
  @content          = content
  @mode             = resolve_mode(mode)
  apply_opts(opts)
  @created_at = Time.now.utc
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def id
  @id
end

#modeObject (readonly)

Returns the value of attribute mode.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def mode
  @mode
end

#salienceObject (readonly)

Returns the value of attribute salience.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def salience
  @salience
end

#source_subsystemObject (readonly)

Returns the value of attribute source_subsystem.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def source_subsystem
  @source_subsystem
end

#topicObject (readonly)

Returns the value of attribute topic.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def topic
  @topic
end

#urgencyObject (readonly)

Returns the value of attribute urgency.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def urgency
  @urgency
end

#voiceObject (readonly)

Returns the value of attribute voice.



12
13
14
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 12

def voice
  @voice
end

Instance Method Details

#background?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 33

def background?
  @urgency < 0.2
end

#condensed_contentObject



23
24
25
26
27
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 23

def condensed_content
  words = @content.split
  keep = [(words.size * CONDENSATION_RATIO).ceil, 1].max
  words.first(keep).join(' ')
end

#decay_salience!Object



37
38
39
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 37

def decay_salience!
  @salience = [@salience - SALIENCE_DECAY, SALIENCE_FLOOR].max
end

#salient?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 41

def salient?
  @salience >= 0.3
end

#to_hObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 50

def to_h
  {
    id:               @id,
    content:          @content,
    condensed:        condensed_content,
    mode:             @mode,
    voice:            @voice,
    topic:            @topic,
    urgency:          @urgency.round(4),
    salience:         @salience.round(4),
    source_subsystem: @source_subsystem,
    urgency_label:    urgency_label
  }
end

#urgency_labelObject



45
46
47
48
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 45

def urgency_label
  URGENCY_LABELS.each { |range, lbl| return lbl if range.cover?(@urgency) }
  :background
end

#urgent?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 29

def urgent?
  @urgency >= 0.6
end