Class: AnalyticalBrain::Tools::AssignNickname

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

Overview

Assigns a static nickname to a sub-agent session. Operates on the session passed through the registry context.

Nicknames must be unique among active siblings — the tool returns an error on collision so the LLM can pick another name naturally, without programmatic suffixes.

Constant Summary collapse

NICKNAME_PATTERN =

Lowercase hyphenated words: “loop-sleuth”, “api-scout”, “test-fixer”

/\A[a-z][a-z0-9]*(-[a-z0-9]+)*\z/
MAX_LENGTH =
30

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tools::Base

schema, truncation_threshold

Constructor Details

#initialize(main_session:) ⇒ AssignNickname

Returns a new instance of AssignNickname.

Parameters:

  • main_session (Session)

    the sub-agent session to name



36
37
38
# File 'lib/analytical_brain/tools/assign_nickname.rb', line 36

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

Class Method Details

.descriptionObject



20
# File 'lib/analytical_brain/tools/assign_nickname.rb', line 20

def self.description = "Assign a permanent nickname to this sub-agent."

.input_schemaObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/analytical_brain/tools/assign_nickname.rb', line 22

def self.input_schema
  {
    type: "object",
    properties: {
      nickname: {
        type: "string",
        description: "Lowercase, hyphenated (e.g. 'loop-sleuth')."
      }
    },
    required: %w[nickname]
  }
end

.tool_nameObject



18
# File 'lib/analytical_brain/tools/assign_nickname.rb', line 18

def self.tool_name = "assign_nickname"

Instance Method Details

#execute(input) ⇒ String, Hash

Parameters:

  • input (Hash<String, Object>)

    with “nickname” key

Returns:

  • (String)

    confirmation message

  • (Hash)

    with :error key on validation failure



43
44
45
46
47
48
49
50
51
# File 'lib/analytical_brain/tools/assign_nickname.rb', line 43

def execute(input)
  nickname = input["nickname"].to_s.strip.downcase

  error = validate(nickname)
  return error if error

  @session.update!(name: nickname)
  "Nickname set to @#{nickname}"
end