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.



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

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.



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

def content
  @content
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#modeObject (readonly)

Returns the value of attribute mode.



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

def mode
  @mode
end

#salienceObject (readonly)

Returns the value of attribute salience.



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

def salience
  @salience
end

#source_subsystemObject (readonly)

Returns the value of attribute source_subsystem.



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

def source_subsystem
  @source_subsystem
end

#topicObject (readonly)

Returns the value of attribute topic.



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

def topic
  @topic
end

#urgencyObject (readonly)

Returns the value of attribute urgency.



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

def urgency
  @urgency
end

#voiceObject (readonly)

Returns the value of attribute voice.



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

def voice
  @voice
end

Instance Method Details

#background?Boolean

Returns:

  • (Boolean)


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

def background?
  @urgency < 0.2
end

#condensed_contentObject



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

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

#decay_salience!Object



48
49
50
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 48

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

#salient?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 52

def salient?
  @salience >= 0.3
end

#to_hObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 61

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



56
57
58
59
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/utterance.rb', line 56

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

#urgent?Boolean

Returns:

  • (Boolean)


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

def urgent?
  @urgency >= 0.6
end