Class: Legion::Extensions::Agentic::Language::InnerSpeech::Helpers::InnerVoice
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Language::InnerSpeech::Helpers::InnerVoice
show all
- Includes:
- Constants
- Defined in:
- lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb
Constant Summary
collapse
- SPEED_MAP =
{
automatic: AUTOMATIC_SPEED,
controlled: CONTROLLED_SPEED,
egocentric: EGOCENTRIC_SPEED
}.freeze
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
Returns a new instance of InnerVoice.
14
15
16
17
18
19
20
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 14
def initialize
@stream = SpeechStream.new
@voices = VOICE_TYPES.dup
@active_voice = :rational
@history = []
@speed = CONTROLLED_SPEED
end
|
Instance Attribute Details
#active_voice ⇒ Object
Returns the value of attribute active_voice.
12
13
14
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 12
def active_voice
@active_voice
end
|
#history ⇒ Object
Returns the value of attribute history.
12
13
14
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 12
def history
@history
end
|
#stream ⇒ Object
Returns the value of attribute stream.
12
13
14
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 12
def stream
@stream
end
|
#voices ⇒ Object
Returns the value of attribute voices.
12
13
14
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 12
def voices
@voices
end
|
Instance Method Details
#break_rumination(redirect_topic:) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 94
def break_rumination(redirect_topic:)
return false unless ruminating?
speak(content: 'Let me think about something else.', mode: :narrating, topic: redirect_topic)
true
end
|
#condensed_narrative ⇒ Object
109
110
111
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 109
def condensed_narrative
@stream.condensed_stream.join(' ')
end
|
#debate(content_a:, content_b:, topic: :general) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 64
def debate(content_a:, content_b:, topic: :general, **)
old_voice = @active_voice
@active_voice = :bold
utt_a = speak(content: content_a, mode: :debating, topic: topic, **)
@active_voice = :cautious
utt_b = speak(content: content_b, mode: :debating, topic: topic, **)
@active_voice = old_voice
[utt_a, utt_b].compact
end
|
#evaluate(content:, topic: :general) ⇒ Object
56
57
58
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 56
def evaluate(content:, topic: :general, **)
speak(content: content, mode: :evaluating, topic: topic, **)
end
|
#interrupt(content:) ⇒ Object
74
75
76
77
78
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 74
def interrupt(content:, **)
utterance = @stream.interrupt(content: content, **)
record_event(:interrupt, utterance_id: utterance&.id) if utterance
utterance
end
|
#narrative ⇒ Object
105
106
107
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 105
def narrative
@stream.narrative
end
|
#plan(content:, topic: :general) ⇒ Object
44
45
46
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 44
def plan(content:, topic: :general, **)
speak(content: content, mode: :planning, topic: topic, **)
end
|
#question(content:, topic: :general) ⇒ Object
52
53
54
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 52
def question(content:, topic: :general, **)
speak(content: content, mode: :questioning, topic: topic, **)
end
|
#recent_speech(count: 5) ⇒ Object
101
102
103
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 101
def recent_speech(count: 5)
@stream.recent(count: count)
end
|
#rehearse(content:, topic: :general) ⇒ Object
48
49
50
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 48
def rehearse(content:, topic: :general, **)
speak(content: content, mode: :rehearsal, topic: topic, **)
end
|
#ruminating? ⇒ Boolean
90
91
92
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 90
def ruminating?
@stream.ruminating?
end
|
#set_speed(mode:) ⇒ Object
86
87
88
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 86
def set_speed(mode:)
@speed = SPEED_MAP.fetch(mode, CONTROLLED_SPEED)
end
|
#speak(content:, mode: :narrating, topic: :general) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 22
def speak(content:, mode: :narrating, topic: :general, **)
utterance = @stream.append(
content: content,
mode: mode,
voice: @active_voice,
topic: topic,
**
)
record_event(:speak, utterance_id: utterance&.id) if utterance
utterance
end
|
#switch_voice(voice:) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 34
def switch_voice(voice:)
sym = voice.to_sym
return nil unless VOICE_TYPES.include?(sym)
old_voice = @active_voice
@active_voice = sym
record_event(:switch_voice, from: old_voice, to: sym)
@active_voice
end
|
#tick ⇒ Object
113
114
115
116
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 113
def tick
@stream.decay_all
@stream.to_h.merge(active_voice: @active_voice, speed: @speed)
end
|
#to_h ⇒ Object
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 118
def to_h
{
active_voice: @active_voice,
speed: @speed,
stream_size: @stream.size,
ruminating: ruminating?,
total_utterances: @stream.counter,
history_size: @history.size
}
end
|
#warn(content:, topic: :general) ⇒ Object
60
61
62
|
# File 'lib/legion/extensions/agentic/language/inner_speech/helpers/inner_voice.rb', line 60
def warn(content:, topic: :general, **)
speak(content: content, mode: :warning, topic: topic, urgency: 0.8, **)
end
|