Class: Protege::Inference::Provider::ToolCall

Inherits:
Data
  • Object
show all
Defined in:
lib/protege/inference/provider/tool_call.rb

Overview

One tool call emitted by the model in a Response (Protege's internal representation).

id: provider-assigned identifier used to correlate the eventual tool-result message back to this call. name: snake_case tool name to invoke. input: parsed input hash matching the tool's input schema.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



14
15
16
# File 'lib/protege/inference/provider/tool_call.rb', line 14

def id
  @id
end

#inputObject (readonly)

Returns the value of attribute input

Returns:

  • (Object)

    the current value of input



14
15
16
# File 'lib/protege/inference/provider/tool_call.rb', line 14

def input
  @input
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



14
15
16
# File 'lib/protege/inference/provider/tool_call.rb', line 14

def name
  @name
end

Class Method Details

.from_wire(hash) ⇒ ToolCall

Build a ToolCall from a function-call wire hash: { id:, type: "function", function: { name:, arguments: <JSON string> } } — the shape the model emits in the response hash. arguments is JSON-decoded into input.

Parameters:

  • hash (Hash)

    the function-call wire hash (symbol keys)

Returns:



25
26
27
28
# File 'lib/protege/inference/provider/tool_call.rb', line 25

def self.from_wire(hash)
  function = hash[:function] || {}
  new(id: hash[:id], name: function[:name], input: parse_arguments(function[:arguments]))
end

.parse_arguments(raw) ⇒ Hash

Decode the JSON arguments string into an input hash (empty when blank).

Parameters:

  • raw (String, nil)

    the JSON-encoded arguments

Returns:

  • (Hash)

    the parsed input



34
35
36
# File 'lib/protege/inference/provider/tool_call.rb', line 34

def self.parse_arguments(raw)
  raw.present? ? JSON.parse(raw) : {}
end

Instance Method Details

#to_wireHash

Render this call in the standard function-call wire shape, with JSON-encoded arguments — the same serialization a request's assistant turn and a trace's response snapshot both use.

Returns:

  • (Hash)

    { id:, type: 'function', function: { name:, arguments: } }



42
43
44
45
46
47
48
# File 'lib/protege/inference/provider/tool_call.rb', line 42

def to_wire
  {
    id:,
    type:     'function',
    function: { name:, arguments: input.to_json }
  }
end