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: ,
  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:)

  # ensure any args passed have a
  # workspace_dir.
  resolved_args = (
    if args.key?(:workspace_dir)
      args
    else
      args.merge(workspace_dir:)
    end
  )

  # If they passed a tool instance, nothing to do
  if value.is_a?(RubyLLM::Tool)
    return value
  elsif value.is_a?(Symbol) || value.is_a?(String)
    # They passed the tool name
    # we must initialize it with
    # the standard args
    tool_name = value.to_sym
    unless available_tools.key?(tool_name)
      raise ArgumentError, "        Unknown tool name: \#{value.inspect}.\n        If you wish to use a custom tool you must configure\n        it by passing `extra_tools` to the Session.\n      TXT\n    end\n\n    klass_or_instance = available_tools.fetch(tool_name)\n\n    if klass_or_instance.is_a?(RubyLLM::Tool)\n      klass_or_instance\n    else\n      klass_or_instance.new(**resolved_args)\n    end\n  elsif value.is_a?(Class) && value.ancestors.include?(RubyLLM::Tool)\n    value.new(**resolved_args)\n  else\n    raise ArgumentError, \"unknown tool specified: \#{value.inspect}\"\n  end\nend\n"