Class: RubynCode::Tools::SpawnTeammate

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

Constant Summary collapse

TOOL_NAME =
'spawn_teammate'
DESCRIPTION =
'Spawn a persistent named teammate agent with a role and an initial task. ' \
'The teammate gets its own conversation, processes the initial prompt, and ' \
'remains available via the mailbox for further messages.'
PARAMETERS =
{
  name: {
    type: :string,
    description: 'Unique name for the teammate',
    required: true
  },
  role: {
    type: :string,
    description: "The teammate's role (e.g. 'coder', 'reviewer', 'tester')",
    required: true
  },
  prompt: {
    type: :string,
    description: 'Initial task or instruction for the teammate',
    required: true
  }
}.freeze
RISK_LEVEL =
:execute

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

#db=(value) ⇒ Object (writeonly)

Sets the attribute db

Parameters:

  • value

    the value to set the attribute db to.



32
33
34
# File 'lib/rubyn_code/tools/spawn_teammate.rb', line 32

def db=(value)
  @db = value
end

#llm_client=(value) ⇒ Object (writeonly)

Sets the attribute llm_client

Parameters:

  • value

    the value to set the attribute llm_client to.



32
33
34
# File 'lib/rubyn_code/tools/spawn_teammate.rb', line 32

def llm_client=(value)
  @llm_client = value
end

#on_status=(value) ⇒ Object (writeonly)

Sets the attribute on_status

Parameters:

  • value

    the value to set the attribute on_status to.



32
33
34
# File 'lib/rubyn_code/tools/spawn_teammate.rb', line 32

def on_status=(value)
  @on_status = value
end

Instance Method Details

#execute(name:, role:, prompt:) ⇒ Object

Raises:



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

def execute(name:, role:, prompt:)
  callback = @on_status || method(:default_status)

  raise Error, 'LLM client not available' unless @llm_client
  raise Error, 'Database not available' unless @db

  mailbox = Teams::Mailbox.new(@db)
  manager = Teams::Manager.new(@db, mailbox: mailbox)

  teammate = manager.spawn(name: name, role: role)
  callback.call(:started, "Spawning teammate '#{name}' as #{role}...")

  Thread.new do
    run_teammate_agent(teammate, prompt, mailbox, callback)
  end

  "Spawned teammate '#{name}' as #{role}. Initial task: #{prompt[0..100]}"
end