Module: AgentC::Tools
- Defined in:
- lib/agent_c/tools.rb,
lib/agent_c/tools/grep.rb,
lib/agent_c/tools/paths.rb,
lib/agent_c/tools/dir_glob.rb,
lib/agent_c/tools/edit_file.rb,
lib/agent_c/tools/read_file.rb,
lib/agent_c/tools/file_metadata.rb,
lib/agent_c/tools/run_rails_test.rb
Defined Under Namespace
Modules: Paths
Classes: DirGlob, EditFile, FileMetadata, Grep, ReadFile, RunRailsTest
Constant Summary
collapse
- NAMES =
{
read_file: ReadFile,
edit_file: EditFile,
grep: Grep,
file_metadata: FileMetadata,
dir_glob: DirGlob,
run_rails_test: RunRailsTest,
}
Class Method Summary
collapse
Class Method Details
.all(**params) ⇒ Object
14
15
16
|
# File 'lib/agent_c/tools.rb', line 14
def self.all(**params)
NAMES.values.map { _1.new(**params) }
end
|
.resolve(value:, available_tools:, args:, workspace_dir:) ⇒ 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
|
# File 'lib/agent_c/tools.rb', line 18
def self.resolve(value:, available_tools:, args:, workspace_dir:)
resolved_args = (
if args.key?(:workspace_dir)
args
else
args.merge(workspace_dir:)
end
)
if value.is_a?(RubyLLM::Tool)
return value
elsif value.is_a?(Symbol) || value.is_a?(String)
tool_name = value.to_sym
unless available_tools.key?(tool_name)
raise ArgumentError, <<~TXT
Unknown tool name: #{value.inspect}.
If you wish to use a custom tool you must configure
it by passing `extra_tools` to the Session.
TXT
end
klass_or_instance = available_tools.fetch(tool_name)
if klass_or_instance.is_a?(RubyLLM::Tool)
klass_or_instance
else
klass_or_instance.new(**resolved_args)
end
elsif value.is_a?(Class) && value.ancestors.include?(RubyLLM::Tool)
value.new(**resolved_args)
else
raise ArgumentError, "unknown tool specified: #{value.inspect}"
end
end
|