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_event_id:, to_event_id:, level: 1) ⇒ SaveSnapshot

Returns a new instance of SaveSnapshot.

Parameters:

  • main_session (Session)

    the session being observed

  • from_event_id (Integer)

    first event ID covered by this snapshot

  • to_event_id (Integer)

    last event ID covered by this snapshot

  • level (Integer) (defaults to: 1)

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



38
39
40
41
42
43
# File 'lib/mneme/tools/save_snapshot.rb', line 38

def initialize(main_session:, from_event_id:, to_event_id:, level: 1, **)
  @main_session = main_session
  @from_event_id = from_event_id
  @to_event_id = to_event_id
  @level = level
end

Class Method Details

.descriptionObject



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

def self.description = "Save a summary of the conversation context " \
"that is about to leave the viewport. Write a concise summary " \
"capturing key decisions, topics discussed, and important context. " \
"Focus on WHAT was decided and WHY, not mechanical details."

.input_schemaObject



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mneme/tools/save_snapshot.rb', line 20

def self.input_schema
  {
    type: "object",
    properties: {
      text: {
        type: "string",
        description: "The summary text. Be concise but preserve key decisions, " \
          "goals discussed, and important context. Max #{Anima::Settings.mneme_max_tokens} tokens."
      }
    },
    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



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mneme/tools/save_snapshot.rb', line 45

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_event_id: @from_event_id,
    to_event_id: @to_event_id,
    level: @level,
    token_count: estimate_tokens(text)
  )

  "Snapshot saved (id: #{snapshot.id}, events #{@from_event_id}..#{@to_event_id})"
end