Class: RubynCode::Tools::SpawnAgent

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

Constant Summary collapse

TOOL_NAME =
'spawn_agent'
DESCRIPTION =
'Spawn an isolated sub-agent to handle a task. The sub-agent gets its own ' \
"fresh context, works independently, and returns only a summary. Use 'explore' " \
"type for research/reading, 'worker' type for writing code/files, or the name " \
'of any custom agent defined in .rubyn-code/agents/. The sub-agent shares the ' \
'filesystem but not your conversation.'
PARAMETERS =
{
  prompt: {
    type: :string,
    description: 'The task for the sub-agent to perform',
    required: true
  },
  agent_type: {
    type: :string,
    description: "Agent type: 'explore' (read-only), 'worker' (full write access), or a " \
                 'custom agent name from .rubyn-code/agents/. Default: explore',
    required: false
  }
}.freeze
RISK_LEVEL =
:execute
READ_TOOLS =
%w[read_file glob grep bash load_skill memory_search].freeze
BLOCKED_TOOLS =
%w[spawn_agent send_message read_inbox compact memory_write].freeze

Constants inherited from Base

Base::REQUIRES_CONFIRMATION

Instance Attribute Summary collapse

Attributes inherited from Base

#project_root

Instance Method Summary collapse

Methods inherited from Base

description, #initialize, parameters, requires_confirmation?, risk_level, #safe_path, summarize, to_schema, tool_name, #truncate

Constructor Details

This class inherits a constructor from RubynCode::Tools::Base

Instance Attribute Details

#llm_client=(value) ⇒ Object (writeonly)

These get injected by the executor or the REPL



34
35
36
# File 'lib/rubyn_code/tools/spawn_agent.rb', line 34

def llm_client=(value)
  @llm_client = value
end

#on_status=(value) ⇒ Object (writeonly)

These get injected by the executor or the REPL



34
35
36
# File 'lib/rubyn_code/tools/spawn_agent.rb', line 34

def on_status=(value)
  @on_status = value
end

Instance Method Details

#execute(prompt:, agent_type: 'explore') ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubyn_code/tools/spawn_agent.rb', line 36

def execute(prompt:, agent_type: 'explore')
  agent = resolve_agent(agent_type)
  callback = @on_status || method(:default_status)
  @tool_count = 0

  callback.call(:started, "Spawning #{agent.name} agent...")

  tools = tools_for(agent)
  result, hit_limit = run_sub_agent(prompt: prompt, tools: tools, agent: agent, callback: callback)

  callback.call(:done, "Agent finished (#{@tool_count} tool calls).")

  summary = RubynCode::SubAgents::Summarizer.call(result, max_length: 3000)
  format_agent_result(agent.name, summary, hit_limit)
end