Class: AnalyticalBrain::Tools::SetGoal

Inherits:
Tools::Base show all
Includes:
GoalMessaging
Defined in:
lib/analytical_brain/tools/set_goal.rb

Overview

Creates a goal on the main session. Root goals represent high-level objectives (semantic episodes); sub-goals are TODO-style steps within a root goal. The two-level hierarchy is enforced by the Goal model.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tools::Base

schema, truncation_threshold

Constructor Details

#initialize(main_session:) ⇒ SetGoal

Returns a new instance of SetGoal.

Parameters:

  • main_session (Session)

    the session to create the goal on



30
31
32
# File 'lib/analytical_brain/tools/set_goal.rb', line 30

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

Class Method Details

.descriptionObject



13
# File 'lib/analytical_brain/tools/set_goal.rb', line 13

def self.description = "Create a goal or sub-goal."

.input_schemaObject



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

def self.input_schema
  {
    type: "object",
    properties: {
      description: {
        type: "string",
        description: "1 sentence."
      },
      parent_goal_id: {type: "integer"}
    },
    required: %w[description]
  }
end

.tool_nameObject



11
# File 'lib/analytical_brain/tools/set_goal.rb', line 11

def self.tool_name = "set_goal"

Instance Method Details

#execute(input) ⇒ String, Hash

Parameters:

  • input (Hash<String, Object>)

    with “description” and optional “parent_goal_id”

Returns:

  • (String)

    confirmation with goal ID

  • (Hash)

    with :error key on validation failure



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/analytical_brain/tools/set_goal.rb', line 37

def execute(input)
  description = input["description"].to_s.strip
  return {error: "Description cannot be blank"} if description.empty?

  goal = @main_session.goals.create!(
    description: description,
    parent_goal_id: input["parent_goal_id"]
  )
  confirmation = format_confirmation(goal)
  enqueue_goal_message(goal, confirmation)
  confirmation
rescue ActiveRecord::RecordInvalid => error
  {error: error.record.errors.full_messages.join(", ")}
end