Class: AnalyticalBrain::Tools::RenameSession

Inherits:
Tools::Base
  • Object
show all
Defined in:
lib/analytical_brain/tools/rename_session.rb

Overview

Renames the main session with an emoji and short descriptive name. Operates on the main session passed through the registry context, not on the phantom analytical brain session.

The analytical brain calls this when a conversation’s topic becomes clear or shifts significantly enough to warrant a new name.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tools::Base

schema

Constructor Details

#initialize(main_session:) ⇒ RenameSession

Returns a new instance of RenameSession.

Parameters:

  • main_session (Session)

    the session to rename



35
36
37
# File 'lib/analytical_brain/tools/rename_session.rb', line 35

def initialize(main_session:, **)
  @main_session = main_session
end

Class Method Details

.descriptionObject



14
15
# File 'lib/analytical_brain/tools/rename_session.rb', line 14

def self.description = "Rename the conversation session. " \
"Use one emoji followed by 1-3 descriptive words."

.input_schemaObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/analytical_brain/tools/rename_session.rb', line 17

def self.input_schema
  {
    type: "object",
    properties: {
      emoji: {
        type: "string",
        description: "A single emoji representing the conversation topic"
      },
      name: {
        type: "string",
        description: "1-3 word descriptive name for the session"
      }
    },
    required: %w[emoji name]
  }
end

.tool_nameObject



12
# File 'lib/analytical_brain/tools/rename_session.rb', line 12

def self.tool_name = "rename_session"

Instance Method Details

#execute(input) ⇒ String, Hash

Parameters:

  • input (Hash<String, Object>)

    with “emoji” and “name” keys

Returns:

  • (String)

    confirmation message

  • (Hash)

    with :error key on validation failure



42
43
44
45
46
47
48
49
# File 'lib/analytical_brain/tools/rename_session.rb', line 42

def execute(input)
  error = validate(input)
  return error if error

  full_name = build_name(input)
  @main_session.update!(name: full_name)
  "Session renamed to: #{full_name}"
end