Class: TurnKit::SubAgentTool

Inherits:
Tool
  • Object
show all
Defined in:
lib/turnkit/sub_agent_tool.rb

Constant Summary

Constants inherited from Tool

Tool::TYPES

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Tool

call, completion_message, description, ends_turn?, parameter, parameters, tool_name

Class Method Details

.for(agent) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/turnkit/sub_agent_tool.rb', line 8

def self.for(agent)
  Class.new(self) do
    @agent = agent
    tool_name agent.name
    description agent.description.empty? ? "Delegate work to #{agent.name}." : agent.description

    class << self
      attr_reader :agent
    end
  end
end

Instance Method Details

#call(task:, context: nil, turnkit_context:) ⇒ Object



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

def call(task:, context: nil, turnkit_context:)
  sub_agent = self.class.agent
  parent_turn = turnkit_context.turn
  conversation = parent_turn.conversation
  prompt = [ task, context ].compact.join("\n\n")
  trigger = conversation.append_message(role: "user", kind: "text", text: prompt, turn_id: parent_turn.id)
  child = conversation.run!(
    trigger_message_id: trigger.id,
    budget: parent_turn.budget,
    parent_turn: parent_turn,
    parent_tool_execution: turnkit_context.execution,
    depth: parent_turn.depth + 1,
    model: sub_agent.effective_model,
    agent: sub_agent
  )
  { "turn_id" => child.id, "status" => child.status, "result" => child.output_text }
end