Class: Ask::Agent::ExitPlanMode

Inherits:
Tool
  • Object
show all
Defined in:
lib/ask/agent/exit_plan_mode.rb

Overview

Presents the model's plan for human approval at the end of plan mode.

Called after research: submits the plan to the session's plan queue and returns a pending result — the agent hands back the interim reply and waits for a human decision. On approval, plan mode turns off and the agent executes the plan; on rejection, it stays in plan mode with the rejection feedback in the conversation.

Injected into the session by Session.new(plan_mode: true).

Instance Method Summary collapse

Constructor Details

#initialize(plan_queue:, on_submit: nil) ⇒ ExitPlanMode

Returns a new instance of ExitPlanMode.

Parameters:

  • plan_queue (Ask::Agent::ApprovalQueue)

    queue carrying plan approvals; the session wires approve/reject callbacks

  • on_submit (Proc, nil) (defaults to: nil)

    called with the plan text when the plan is submitted (used to emit PlanProposed)



27
28
29
30
31
# File 'lib/ask/agent/exit_plan_mode.rb', line 27

def initialize(plan_queue:, on_submit: nil)
  @plan_queue = plan_queue
  @on_submit = on_submit
  super()
end

Instance Method Details

#execute(plan:) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ask/agent/exit_plan_mode.rb', line 33

def execute(plan:)
  tool_call_id = Thread.current[:ask_agent_tool_call_id]
  @plan_queue.submit(
    tool_call_id: tool_call_id,
    tool_name: "exit_plan_mode",
    args: { plan: plan.to_s },
    auto_approvable: false,
    message: "Plan submitted for approval"
  )
  @on_submit&.call(plan.to_s)
  Ask::Result.pending("Plan submitted for approval — waiting for a human decision")
end