Class: LLM::Tool::Which

Inherits:
LLM::Tool show all
Defined in:
lib/llm/tools/which.rb

Overview

The LLM::Tool::Which class implements a tool that locates an executable on the system PATH.

This lets an agent discover whether a command it intends to use is actually available before attempting to run it. For example, checking which("rg") before a search, or which("git") before a version control operation, avoids a failed subprocess and lets the agent adapt its strategy when a tool is missing.

Instance Method Summary collapse

Methods inherited from LLM::Tool

a2a, a2a?, #a2a?, clear_registry!, description, find_by_name!, function, #function, inherited, mcp, mcp?, #mcp?, name, #on_cancel, #on_interrupt, params, register, registry, skill?, #skill?, unregister

Methods included from Param

#param, #required

Methods included from Function::Registry

#clear_registry!, extended, #find_by_name, #lock, #register, #registry, #registry_key, #tool_name, #unregister

Instance Method Details

#call(name:) ⇒ Hash

Parameters:

  • name (String)

Returns:

  • (Hash)


23
24
25
26
# File 'lib/llm/tools/which.rb', line 23

def call(name:)
  path = paths.find { File.executable? File.join(_1, name) }
  {ok: !!path, path:}
end