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



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

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

Class Method Details

.descriptionObject



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

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

.input_schemaObject



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

def self.input_schema
  {
    type: "object",
    properties: {
      description: {
        type: "string",
        description: "1 sentence."
      },
      parent_goal_id: {type: "integer"}
    },
    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



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/analytical_brain/tools/set_goal.rb', line 35

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