Class: Raif::Messages::ToolCallResult

Inherits:
Object
  • Object
show all
Defined in:
lib/raif/messages.rb

Overview

Result of a tool invocation

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result:, provider_tool_call_id: nil, name: nil) ⇒ ToolCallResult

Returns a new instance of ToolCallResult.

Parameters:

  • result (Hash, String)

    The result returned by the tool

  • provider_tool_call_id (String, nil) (defaults to: nil)

    Provider-assigned ID matching the tool call

  • name (String, nil) (defaults to: nil)

    The tool name (required by some providers like Google)



125
126
127
128
129
# File 'lib/raif/messages.rb', line 125

def initialize(result:, provider_tool_call_id: nil, name: nil)
  @provider_tool_call_id = provider_tool_call_id
  @name = name
  @result = result
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



120
121
122
# File 'lib/raif/messages.rb', line 120

def name
  @name
end

#provider_tool_call_idObject (readonly)

Returns the value of attribute provider_tool_call_id.



120
121
122
# File 'lib/raif/messages.rb', line 120

def provider_tool_call_id
  @provider_tool_call_id
end

#resultObject (readonly)

Returns the value of attribute result.



120
121
122
# File 'lib/raif/messages.rb', line 120

def result
  @result
end

Class Method Details

.from_h(hash) ⇒ ToolCallResult

Deserialize from a hash

Parameters:

  • hash (Hash)

    A hash with tool call result fields

Returns:



144
145
146
147
148
149
150
# File 'lib/raif/messages.rb', line 144

def self.from_h(hash)
  new(
    provider_tool_call_id: hash["provider_tool_call_id"],
    name: hash["name"],
    result: hash["result"]
  )
end

Instance Method Details

#to_hHash

Returns Hash representation for JSONB storage and LLM APIs.

Returns:

  • (Hash)

    Hash representation for JSONB storage and LLM APIs



132
133
134
135
136
137
138
139
# File 'lib/raif/messages.rb', line 132

def to_h
  {
    "type" => "tool_call_result",
    "provider_tool_call_id" => provider_tool_call_id,
    "name" => name,
    "result" => result
  }.compact
end