Class: OpenRouter::ResponsesToolResult

Inherits:
Object
  • Object
show all
Includes:
ToolResultBase
Defined in:
lib/open_router/responses_tool_call.rb

Overview

Represents the result of executing a Responses API tool call

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ToolResultBase

#failure?, included, #success?

Constructor Details

#initialize(tool_call, result = nil, error = nil) ⇒ ResponsesToolResult

Returns a new instance of ResponsesToolResult.



64
65
66
67
68
69
# File 'lib/open_router/responses_tool_call.rb', line 64

def initialize(tool_call, result = nil, error = nil)
  @tool_call = tool_call
  @result = result
  @error = error
  @output_id = "fc_output_#{SecureRandom.hex(8)}"
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



62
63
64
# File 'lib/open_router/responses_tool_call.rb', line 62

def error
  @error
end

#output_idObject (readonly)

Returns the value of attribute output_id.



62
63
64
# File 'lib/open_router/responses_tool_call.rb', line 62

def output_id
  @output_id
end

#resultObject (readonly)

Returns the value of attribute result.



62
63
64
# File 'lib/open_router/responses_tool_call.rb', line 62

def result
  @result
end

#tool_callObject (readonly)

Returns the value of attribute tool_call.



62
63
64
# File 'lib/open_router/responses_tool_call.rb', line 62

def tool_call
  @tool_call
end

Instance Method Details

#to_hObject



91
92
93
# File 'lib/open_router/responses_tool_call.rb', line 91

def to_h
  to_input_item
end

#to_input_itemHash

Convert to function_call_output format for conversation continuation

Returns:

  • (Hash)

    The output item for the input array



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/open_router/responses_tool_call.rb', line 74

def to_input_item
  output_content = if @error
                     { error: @error }.to_json
                   elsif @result.is_a?(String)
                     @result
                   else
                     @result.to_json
                   end

  {
    "type" => "function_call_output",
    "id" => @output_id,
    "call_id" => @tool_call.call_id,
    "output" => output_content
  }
end

#to_json(*args) ⇒ Object



95
96
97
# File 'lib/open_router/responses_tool_call.rb', line 95

def to_json(*args)
  to_h.to_json(*args)
end