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
|
# File 'lib/brute/tools/delegate.rb', line 19
def execute(task:)
provider = Brute.provider
llm = provider.ruby_llm_provider
model_id = provider.default_model
model = Brute::Middleware::ModelRef.new(model_id, 16_384)
sub_tools = { read: FSRead.new, fs_search: FSSearch.new }
messages = [
RubyLLM::Message.new(
role: :system,
content: "You are a research agent. Analyze code, explain patterns, and answer questions. " \
"You have read-only access to the filesystem. Be thorough and precise."
),
RubyLLM::Message.new(role: :user, content: task),
]
response = nil
MAX_ROUNDS.times do
response = llm.complete(messages, tools: sub_tools, temperature: nil, model: model)
messages << response
break unless response.tool_call?
response.tool_calls.each_value do |tc|
tool = sub_tools[tc.name.to_sym]
result = if tool
tool.call(tc.arguments)
else
{ error: "Unknown tool: #{tc.name}" }
end
content = result.is_a?(String) ? result : result.to_s
messages << RubyLLM::Message.new(role: :tool, content: content, tool_call_id: tc.id)
end
end
{ result: (response, messages) }
end
|