Class: AnalyticalBrain::Tools::UpdateGoal

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

Overview

Updates a goal’s description on the main session.

The analytical brain creates goals early when intent is vague, then refines them as the conversation clarifies scope — e.g. “implement auth” becomes “implement OAuth2 middleware for API endpoints”. Without this tool the brain would have to choose between keeping a stale description or creating a duplicate goal.

Completed goals cannot be updated; attempting to do so returns an error so the brain learns to check status before calling this tool.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tools::Base

schema, truncation_threshold

Constructor Details

#initialize(main_session:) ⇒ UpdateGoal

Returns a new instance of UpdateGoal.

Parameters:

  • main_session (Session)

    the session owning the goal



37
38
39
# File 'lib/analytical_brain/tools/update_goal.rb', line 37

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

Class Method Details

.descriptionObject



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

def self.description = "Refine a goal's wording as understanding evolves."

.input_schemaObject



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

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

.tool_nameObject



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

def self.tool_name = "update_goal"

Instance Method Details

#execute(input) ⇒ String, Hash

Parameters:

  • input (Hash<String, Object>)

    with “goal_id” and “description”

Returns:

  • (String)

    confirmation message

  • (Hash)

    with :error key on failure



44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/analytical_brain/tools/update_goal.rb', line 44

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

  goal = @main_session.goals.find_by(id: goal_id)
  return {error: "Goal not found (id: #{goal_id})"} unless goal
  return {error: "Cannot update completed goal: #{goal.description} (id: #{goal_id})"} if goal.completed?

  goal.update!(description: description)
  confirmation = "Goal updated: #{description} (id: #{goal_id})"
  enqueue_goal_message(goal, confirmation)
  confirmation
end