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



28
29
30
# File 'lib/analytical_brain/tools/rename_session.rb', line 28

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

Class Method Details

.descriptionObject



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

def self.description = "Rename the session."

.input_schemaObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/analytical_brain/tools/rename_session.rb', line 16

def self.input_schema
  {
    type: "object",
    properties: {
      emoji: {type: "string"},
      name: {type: "string", description: "1-3 words."}
    },
    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



35
36
37
38
39
40
41
42
# File 'lib/analytical_brain/tools/rename_session.rb', line 35

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