Class: Tools::MarkGoalCompleted

Inherits:
Base
  • Object
show all
Defined in:
lib/tools/mark_goal_completed.rb

Overview

Signals sub-agent task completion by marking its assigned Goal as completed and routing the result back to the parent session.

Only available to sub-agent sessions (those with a parent_session). This is the explicit “finish line” that prevents runaway sub-agents from continuing past their assigned task.

The result text is delivered to the parent session as a user message attributed to the sub-agent, identical to how regular sub-agent messages are routed by Events::Subscribers::SubagentMessageRouter.

Examples:

Sub-agent completing its task

mark_goal_completed(result: "Found 3 N+1 queries in the orders controller.")

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

schema, truncation_threshold

Constructor Details

#initialize(session:) ⇒ MarkGoalCompleted

Returns a new instance of MarkGoalCompleted.

Parameters:

  • session (Session)

    the sub-agent session



33
34
35
# File 'lib/tools/mark_goal_completed.rb', line 33

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

Class Method Details

.descriptionObject



20
# File 'lib/tools/mark_goal_completed.rb', line 20

def self.description = "Deliver result to parent. Stop working after this call."

.input_schemaObject



22
23
24
25
26
27
28
29
30
# File 'lib/tools/mark_goal_completed.rb', line 22

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

.tool_nameObject



18
# File 'lib/tools/mark_goal_completed.rb', line 18

def self.tool_name = "mark_goal_completed"

Instance Method Details

#execute(input) ⇒ String, Hash{Symbol => String}

Completes the sub-agent’s assigned goal and routes the result to the parent session.

Parameters:

  • input (Hash<String, Object>)

    with “result”

Returns:

  • (String)

    confirmation message

  • (Hash{Symbol => String})

    with :error key on failure



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tools/mark_goal_completed.rb', line 43

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

  goal = @session.goals.active.root.first
  return {error: "No active goal found"} unless goal

  complete_goal(goal)
  route_result_to_parent(result)

  "Done. Result delivered to parent."
end