Class: AnalyticalBrain::Tools::SetGoal

Inherits:
Tools::Base show all
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

Constructor Details

#initialize(main_session:) ⇒ SetGoal

Returns a new instance of SetGoal.

Parameters:

  • main_session (Session)

    the session to create the goal on



32
33
34
# File 'lib/analytical_brain/tools/set_goal.rb', line 32

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

Class Method Details

.descriptionObject



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

def self.description = "Create a goal on the main session. " \
"Omit parent_goal_id for a root goal, or provide it to create a sub-goal (TODO item)."

.input_schemaObject



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

def self.input_schema
  {
    type: "object",
    properties: {
      description: {
        type: "string",
        description: "What needs to be accomplished (1-2 sentences)"
      },
      parent_goal_id: {
        type: "integer",
        description: "ID of the parent goal (omit for root goals)"
      }
    },
    required: %w[description]
  }
end

.tool_nameObject



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

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



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

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"]
  )
  format_confirmation(goal)
rescue ActiveRecord::RecordInvalid => error
  {error: error.record.errors.full_messages.join(", ")}
end