Class: LLM::Tool::Ruby

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

Overview

The LLM::Tool::Ruby tool evaluates a string of Ruby code by spawning a Ruby process with -e option.

Instance Method Summary collapse

Methods inherited from LLM::Tool

NotFound, a2a, a2a?, #a2a?, abstract!, abstract?, clear_registry!, description, find_by_name!, #function, function, inherited, mcp, #mcp?, mcp?, name, #on_cancel, #on_interrupt, params, register, registry, set, subclasses, unregister

Methods included from Param

#defaults, #param, #required

Methods included from Function::Registry

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

Instance Method Details

#call(code:, timeout: 15, max_bytes: Exec.max_bytes) ⇒ Hash

Parameters:

  • code (String) —

    Ruby code

  • timeout (Integer) (defaults to: 15) —

    Runtime timeout

  • max_bytes (Integer) (defaults to: Exec.max_bytes) —

    Max bytes to emit

Returns:

  • (Hash)


30
31
32
33
34
35
36
37
# File 'lib/llm/tools/ruby.rb', line 30

def call(code:, timeout: 15, max_bytes: Exec.max_bytes)
  Exec.new.call(
    command: RbConfig.ruby,
    arguments: ["-e", code],
    timeout:,
    max_bytes:
  )
end