Class: Raif::Messages::ToolCall

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

Overview

Tool invocation request from the assistant

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, arguments:, provider_tool_call_id: nil, assistant_message: nil, provider_metadata: nil) ⇒ ToolCall

Returns a new instance of ToolCall.

Parameters:

  • name (String)

    The tool name (snake_case)

  • arguments (Hash)

    The arguments passed to the tool

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

    Provider-assigned ID for the tool call

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

    Optional assistant message accompanying the tool call

  • provider_metadata (Hash, nil) (defaults to: nil)

    Provider-specific metadata (e.g., Google’s thoughtSignature)



84
85
86
87
88
89
90
# File 'lib/raif/messages.rb', line 84

def initialize(name:, arguments:, provider_tool_call_id: nil, assistant_message: nil, provider_metadata: nil)
  @provider_tool_call_id = provider_tool_call_id
  @name = name
  @arguments = arguments
  @assistant_message = assistant_message
  @provider_metadata = 
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



77
78
79
# File 'lib/raif/messages.rb', line 77

def arguments
  @arguments
end

#assistant_messageObject (readonly)

Returns the value of attribute assistant_message.



77
78
79
# File 'lib/raif/messages.rb', line 77

def assistant_message
  @assistant_message
end

#nameObject (readonly)

Returns the value of attribute name.



77
78
79
# File 'lib/raif/messages.rb', line 77

def name
  @name
end

#provider_metadataObject (readonly)

Returns the value of attribute provider_metadata.



77
78
79
# File 'lib/raif/messages.rb', line 77

def 
  @provider_metadata
end

#provider_tool_call_idObject (readonly)

Returns the value of attribute provider_tool_call_id.



77
78
79
# File 'lib/raif/messages.rb', line 77

def provider_tool_call_id
  @provider_tool_call_id
end

Class Method Details

.from_h(hash) ⇒ ToolCall

Deserialize from a hash

Parameters:

  • hash (Hash)

    A hash with tool call fields

Returns:



107
108
109
110
111
112
113
114
115
# File 'lib/raif/messages.rb', line 107

def self.from_h(hash)
  new(
    name: hash["name"],
    arguments: hash["arguments"],
    provider_tool_call_id: hash["provider_tool_call_id"],
    assistant_message: hash["assistant_message"],
    provider_metadata: hash["provider_metadata"]
  )
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



93
94
95
96
97
98
99
100
101
102
# File 'lib/raif/messages.rb', line 93

def to_h
  {
    "type" => "tool_call",
    "provider_tool_call_id" => provider_tool_call_id,
    "name" => name,
    "arguments" => arguments,
    "assistant_message" => assistant_message,
    "provider_metadata" => 
  }.compact
end