Class: WriteTool

Inherits:
LlmGateway::Tool show all
Defined in:
lib/llm_gateway/agents/tools/write_tool.rb

Instance Method Summary collapse

Methods inherited from LlmGateway::Tool

cache, definition, description, #initialize, input_schema, name, tool_name, #tool_result

Constructor Details

This class inherits a constructor from LlmGateway::Tool

Instance Method Details

#execute(input, tool_use_id:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/llm_gateway/agents/tools/write_tool.rb', line 20

def execute(input, tool_use_id:)
  path = input[:path] || input["path"]
  content = input[:content] || input["content"]

  absolute_path = ToolUtils.resolve_to_cwd(path)

  ToolUtils.with_file_mutation_lock(absolute_path) do
    FileUtils.mkdir_p(File.dirname(absolute_path))
    File.write(absolute_path, content)
  end

  tool_result("Successfully wrote #{content.bytesize} bytes to #{path}", tool_use_id: tool_use_id)
rescue StandardError => e
  tool_result(e.message, tool_use_id: tool_use_id)
end