Class: AnalyticalBrain::Tools::UpdateGoal

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

Constructor Details

#initialize(main_session:) ⇒ UpdateGoal

Returns a new instance of UpdateGoal.

Parameters:

  • main_session (Session)

    the session owning the goal



39
40
41
# File 'lib/analytical_brain/tools/update_goal.rb', line 39

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

Class Method Details

.descriptionObject



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

def self.description = "Update a goal's description. " \
"Use this to refine a goal as understanding evolves."

.input_schemaObject



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

def self.input_schema
  {
    type: "object",
    properties: {
      goal_id: {
        type: "integer",
        description: "ID of the goal to update"
      },
      description: {
        type: "string",
        description: "New description for the goal (1-2 sentences)"
      }
    },
    required: %w[goal_id description]
  }
end

.tool_nameObject



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

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



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

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)
  "Goal updated: #{description} (id: #{goal_id})"
end