Class: LangGraphRB::ToolBase

Inherits:
Object
  • Object
show all
Extended by:
ToolDefinition
Defined in:
lib/langgraph_rb/tool_definition.rb

Overview

Base class for tools using the ToolDefinition mixin

Instance Method Summary collapse

Methods included from ToolDefinition

define_function, extended, tool_functions

Instance Method Details

#call(call_args) ⇒ Object

Raises:

  • (ArgumentError)


64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/langgraph_rb/tool_definition.rb', line 64

def call(call_args)
  # call_args: { name:, arguments: {} } or OpenAI-like hash
  name = call_args[:name] || call_args['name']
  args = call_args[:arguments] || call_args['arguments'] || {}
  raise ArgumentError, 'Tool call missing name' if name.nil?

  method_name = name.to_sym
  unless respond_to?(method_name)
    raise ArgumentError, "Undefined tool function: #{name}"
  end

  result = public_send(method_name, **symbolize_keys(args))
  tool_response(result)
end

#to_openai_tool_schemaObject



84
85
86
# File 'lib/langgraph_rb/tool_definition.rb', line 84

def to_openai_tool_schema
  self.class.to_openai_tool_schema
end

#tool_response(payload) ⇒ Object

Standardize tool responses; can be overridden by subclasses



80
81
82
# File 'lib/langgraph_rb/tool_definition.rb', line 80

def tool_response(payload)
  payload
end