Class: LlmGateway::Tool

Inherits:
Object show all
Defined in:
lib/llm_gateway/tool.rb

Direct Known Subclasses

BashTool, EditTool, ReadTool, WriteTool

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*_args, **_kwargs) ⇒ Tool

Returns a new instance of Tool.



7
8
9
# File 'lib/llm_gateway/tool.rb', line 7

def initialize(*_args, **_kwargs)
  # Empty constructor to allow subclasses to call super.
end

Class Method Details

.cache(value = nil) ⇒ Object



26
27
28
29
# File 'lib/llm_gateway/tool.rb', line 26

def self.cache(value = nil)
  @cache = value if value
  @cache
end

.definitionObject



31
32
33
34
35
36
37
38
# File 'lib/llm_gateway/tool.rb', line 31

def self.definition
  {
    name: @name,
    description: @description,
    input_schema: @input_schema,
    cache_control: @cache ? { type: "ephemeral" } : nil
  }.compact
end

.description(value = nil) ⇒ Object



16
17
18
19
# File 'lib/llm_gateway/tool.rb', line 16

def self.description(value = nil)
  @description = value if value
  @description
end

.input_schema(value = nil) ⇒ Object



21
22
23
24
# File 'lib/llm_gateway/tool.rb', line 21

def self.input_schema(value = nil)
  @input_schema = value if value
  @input_schema
end

.name(value = nil) ⇒ Object



11
12
13
14
# File 'lib/llm_gateway/tool.rb', line 11

def self.name(value = nil)
  @name = value if value
  @name
end

.tool_nameObject



40
41
42
# File 'lib/llm_gateway/tool.rb', line 40

def self.tool_name
  definition[:name]
end

Instance Method Details

#execute(input, tool_use_id:) ⇒ Object

Raises:

  • (NotImplementedError)


51
52
53
# File 'lib/llm_gateway/tool.rb', line 51

def execute(input, tool_use_id:)
  raise NotImplementedError, "Subclasses must implement execute"
end

#tool_result(content, tool_use_id:) ⇒ Object



44
45
46
47
48
49
# File 'lib/llm_gateway/tool.rb', line 44

def tool_result(content, tool_use_id:)
  LlmGateway::Agents::Event::ToolCallResult.new(
    tool_use_id: tool_use_id,
    content: content
  )
end