Class: Insika::Tools::Subagents

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/insika/tools/subagents.rb

Overview

PARALLEL fan-out of child agents: delegate N self-contained tasks at once and get all answers back together, in ONE parent turn. Sibling of spawn_subagent (single); this one always sync-joins — the children run concurrently (their provider waits overlap on the reactor) and the combined result comes back as this tool's result. A system tool wired by the ChatBuilder when profile.subagents is present; require "ruby_llm" stays in this file (loaded lazily in create_chat). NOT enveloped (children live in the parent's envelope, same as the sync single).

Instance Method Summary collapse

Constructor Details

#initialize(runner:, state:) ⇒ Subagents

Returns a new instance of Subagents.



47
48
49
50
51
52
# File 'lib/insika/tools/subagents.rb', line 47

def initialize(runner:, state:)
  @runner = runner
  @state = state
  @allowed = Array(state.profile.subagents).map(&:to_s)
  super()
end

Instance Method Details

#descriptionObject

Same reason as spawn_subagent: the parent's allowlist is per-turn data, so the ids are named per instance — in the description and as an enum on each task's agent. See Tools::AgentEnum.



57
58
59
60
61
# File 'lib/insika/tools/subagents.rb', line 57

def description
  return super if @allowed.empty?

  "#{super} Agents you may spawn: #{@allowed.join(', ')}."
end

#execute(tasks:) ⇒ Object

-> { results: [text:, session_id: | error:] } | { error: }. Never raises: a bad envelope / per-task failure is a message to the model.



69
70
71
72
73
74
# File 'lib/insika/tools/subagents.rb', line 69

def execute(tasks:)
  result = @runner.run_subagents(tasks: Array(tasks), parent_state: @state)
  return { error: result[:error] } if result[:error]

  { results: result[:results] }
end

#nameObject

otherwise RubyLLM derives "insika--tools--subagents" from the class name.



45
# File 'lib/insika/tools/subagents.rb', line 45

def name = "spawn_subagents"

#params_schemaObject



63
64
65
# File 'lib/insika/tools/subagents.rb', line 63

def params_schema
  @agent_enum_schema ||= Insika::Tools::AgentEnum.inject(super, @allowed, path: %i[tasks agent])
end