Class: Mneme::Tools::SaveSnapshot
Overview
Saves a summary snapshot of conversation context that is about to leave the viewport. The snapshot captures the “gist” of what happened so the agent retains awareness of past context.
The text field has a max_tokens limit for predictable sizing — each snapshot is a fixed-size tile, enabling calculation of how many fit at each compression level.
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Tools::Base
schema, truncation_threshold
Constructor Details
#initialize(main_session:, from_message_id:, to_message_id:, level: 1) ⇒ SaveSnapshot
Returns a new instance of SaveSnapshot.
34
35
36
37
38
39
|
# File 'lib/mneme/tools/save_snapshot.rb', line 34
def initialize(main_session:, from_message_id:, to_message_id:, level: 1, **)
@main_session = main_session
@from_message_id = from_message_id
@to_message_id = to_message_id
@level = level
end
|
Class Method Details
.description ⇒ Object
15
|
# File 'lib/mneme/tools/save_snapshot.rb', line 15
def self.description = "Summarize what's leaving the viewport."
|
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/mneme/tools/save_snapshot.rb', line 17
def self.input_schema
{
type: "object",
properties: {
text: {
type: "string",
maxLength: Anima::Settings.mneme_max_tokens * Message::BYTES_PER_TOKEN
}
},
required: %w[text]
}
end
|
13
|
# File 'lib/mneme/tools/save_snapshot.rb', line 13
def self.tool_name = "save_snapshot"
|
Instance Method Details
#execute(input) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/mneme/tools/save_snapshot.rb', line 41
def execute(input)
text = input["text"].to_s.strip
return "Error: Summary text cannot be blank" if text.empty?
snapshot = @main_session.snapshots.create!(
text: text,
from_message_id: @from_message_id,
to_message_id: @to_message_id,
level: @level,
token_count: estimate_tokens(text)
)
"Snapshot saved (id: #{snapshot.id}, messages #{@from_message_id}..#{@to_message_id})"
end
|