Class: Mneme::Tools::SaveSnapshot

Inherits:
Tools::Base show all
Defined in:
lib/mneme/tools/save_snapshot.rb

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

Constructor Details

#initialize(main_session:, from_message_id:, to_message_id:, level: 1) ⇒ SaveSnapshot

Returns a new instance of SaveSnapshot.

Parameters:

  • main_session (Session)

    the session being observed

  • from_message_id (Integer)

    first message ID covered by this snapshot

  • to_message_id (Integer)

    last message ID covered by this snapshot

  • level (Integer) (defaults to: 1)

    compression level (1 = from messages, 2 = from L1 snapshots)



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

.descriptionObject



15
# File 'lib/mneme/tools/save_snapshot.rb', line 15

def self.description = "Summarize what's leaving the viewport."

.input_schemaObject



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

.tool_nameObject



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