Class: ClaudeSwarm::Tools::TaskTool

Inherits:
FastMcp::Tool
  • Object
show all
Defined in:
lib/claude_swarm/tools/task_tool.rb

Instance Method Summary collapse

Instance Method Details

#call(prompt:, new_session: false, system_prompt: nil, description: nil, thinking_budget: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/claude_swarm/tools/task_tool.rb', line 18

def call(prompt:, new_session: false, system_prompt: nil, description: nil, thinking_budget: nil)
  executor = ClaudeMcpServer.executor
  instance_config = ClaudeMcpServer.instance_config

  # Prepend thinking budget to prompt if provided
  final_prompt = if thinking_budget
    "#{thinking_budget}: #{prompt}"
  else
    prompt
  end

  options = {
    new_session: new_session,
    system_prompt: system_prompt || instance_config[:prompt],
    description: description,
  }

  # Add allowed tools from instance config
  options[:allowed_tools] = instance_config[:allowed_tools] if instance_config[:allowed_tools]&.any?

  # Add disallowed tools from instance config
  options[:disallowed_tools] = instance_config[:disallowed_tools] if instance_config[:disallowed_tools]&.any?

  # Add connections from instance config
  options[:connections] = instance_config[:connections] if instance_config[:connections]&.any?

  response = executor.execute(final_prompt, options)

  # Validate the response has a result
  unless response.is_a?(Hash) && response.key?("result")
    raise "Invalid response from executor: missing 'result' field. Response structure: #{response.keys.join(", ")}"
  end

  result = response["result"]

  # Validate the result is not empty
  if result.nil? || (result.is_a?(String) && result.strip.empty?)
    raise "Agent #{instance_config[:name]} returned an empty response. The task was executed but no content was provided."
  end

  # Return just the result text as expected by MCP
  result
end