Class: Tools::ReturnResult
Overview
Sub-agent-only tool that delivers a completed result back to the parent session as a tool_call/tool_response pair. The parent agent sees it as if it called a tool itself — no custom event types needed.
Never registered for main sessions — only sub-agents see this tool.
Class Method Summary collapse
Instance Method Summary collapse
-
#execute(input) ⇒ String, Hash
Emits a tool_call/tool_response pair in the parent session so the parent agent sees the sub-agent result as a regular tool interaction.
-
#initialize(session:) ⇒ ReturnResult
constructor
A new instance of ReturnResult.
Methods inherited from Base
Constructor Details
#initialize(session:) ⇒ ReturnResult
Returns a new instance of ReturnResult.
29 30 31 |
# File 'lib/tools/return_result.rb', line 29 def initialize(session:, **) @session = session end |
Class Method Details
.description ⇒ Object
12 13 |
# File 'lib/tools/return_result.rb', line 12 def self.description = "Return your completed result to the parent agent. " \ "Call this when you have fulfilled the assigned task." |
.input_schema ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/tools/return_result.rb', line 15 def self.input_schema { type: "object", properties: { result: { type: "string", description: "The completed deliverable to send back to the parent agent" } }, required: ["result"] } end |
.tool_name ⇒ Object
10 |
# File 'lib/tools/return_result.rb', line 10 def self.tool_name = "return_result" |
Instance Method Details
#execute(input) ⇒ String, Hash
Emits a tool_call/tool_response pair in the parent session so the parent agent sees the sub-agent result as a regular tool interaction.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/tools/return_result.rb', line 38 def execute(input) result = input["result"].to_s.strip return {error: "Result cannot be blank"} if result.empty? parent = @session.parent_session return {error: "No parent session — only sub-agents can return results"} unless parent tool_use_id = "toolu_subagent_#{@session.id}" task = extract_task # Specialists are spawned with a name from the registry; generic sub-agents have nil name. origin_tool = @session.name ? SpawnSpecialist.tool_name : SpawnSubagent.tool_name Events::Bus.emit(Events::ToolCall.new( content: "Sub-agent result (session #{@session.id})", tool_name: origin_tool, tool_input: {"task" => task, "session_id" => @session.id}, tool_use_id: tool_use_id, session_id: parent.id )) Events::Bus.emit(Events::ToolResponse.new( content: result, tool_name: origin_tool, tool_use_id: tool_use_id, session_id: parent.id )) "Result delivered to parent session #{parent.id}." end |