Class: OpenRouter::ToolResult

Inherits:
Object
  • Object
show all
Defined in:
lib/open_router/tool_call.rb

Overview

Represents the result of executing a tool call

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ToolResult.



151
152
153
154
155
# File 'lib/open_router/tool_call.rb', line 151

def initialize(tool_call, result = nil, error = nil)
  @tool_call = tool_call
  @result = result
  @error = error
end

Instance Attribute Details

#errorObject (readonly)

Returns the value of attribute error.



149
150
151
# File 'lib/open_router/tool_call.rb', line 149

def error
  @error
end

#resultObject (readonly)

Returns the value of attribute result.



149
150
151
# File 'lib/open_router/tool_call.rb', line 149

def result
  @result
end

#tool_callObject (readonly)

Returns the value of attribute tool_call.



149
150
151
# File 'lib/open_router/tool_call.rb', line 149

def tool_call
  @tool_call
end

Class Method Details

.failure(tool_call, error) ⇒ Object

Create a failed result



171
172
173
# File 'lib/open_router/tool_call.rb', line 171

def self.failure(tool_call, error)
  new(tool_call, nil, error)
end

.success(tool_call, result) ⇒ Object

Create a successful result



176
177
178
# File 'lib/open_router/tool_call.rb', line 176

def self.success(tool_call, result)
  new(tool_call, result, nil)
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


161
162
163
# File 'lib/open_router/tool_call.rb', line 161

def failure?
  !success?
end

#success?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/open_router/tool_call.rb', line 157

def success?
  @error.nil?
end

#to_messageObject

Convert to message format for conversation continuation



166
167
168
# File 'lib/open_router/tool_call.rb', line 166

def to_message
  @tool_call.to_result_message(@error || @result)
end