Class: AnalyticalBrain::Tools::FinishGoal

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

Overview

Marks a goal as completed on the main session. Sets the status to “completed” and records the completion timestamp.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tools::Base

schema, truncation_threshold

Constructor Details

#initialize(main_session:) ⇒ FinishGoal

Returns a new instance of FinishGoal.

Parameters:

  • main_session (Session)

    the session owning the goal



23
24
25
# File 'lib/analytical_brain/tools/finish_goal.rb', line 23

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

Class Method Details

.descriptionObject



10
# File 'lib/analytical_brain/tools/finish_goal.rb', line 10

def self.description = "Mark a goal as completed."

.input_schemaObject



12
13
14
15
16
17
18
19
20
# File 'lib/analytical_brain/tools/finish_goal.rb', line 12

def self.input_schema
  {
    type: "object",
    properties: {
      goal_id: {type: "integer"}
    },
    required: %w[goal_id]
  }
end

.tool_nameObject



8
# File 'lib/analytical_brain/tools/finish_goal.rb', line 8

def self.tool_name = "finish_goal"

Instance Method Details

#execute(input) ⇒ String, Hash

Parameters:

  • input (Hash<String, Object>)

    with “goal_id”

Returns:

  • (String)

    confirmation message

  • (Hash)

    with :error key on failure



30
31
32
33
34
35
36
# File 'lib/analytical_brain/tools/finish_goal.rb', line 30

def execute(input)
  goal_id = input["goal_id"]
  goal = @main_session.goals.find_by(id: goal_id)
  return {error: "Goal not found (id: #{goal_id})"} unless goal

  complete(goal)
end