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
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,
}
options[:allowed_tools] = instance_config[:allowed_tools] if instance_config[:allowed_tools]&.any?
options[:disallowed_tools] = instance_config[:disallowed_tools] if instance_config[:disallowed_tools]&.any?
options[:connections] = instance_config[:connections] if instance_config[:connections]&.any?
response = executor.execute(final_prompt, options)
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"]
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
result
end
|