Class: RubyLLM::ServerToolCall

Inherits:
Object
  • Object
show all
Includes:
RubyLLM::Support::Inspectable
Defined in:
lib/ruby_llm/server_tool_call.rb

Overview

A ServerToolCall records one provider-executed tool step in an assistant response: a web search the model ran, a code execution, or the results block a provider returned for one. They appear on Message#server_tool_calls when a chat enables tools with Chat#with_provider_tools.

response = chat.with_provider_tools(:web_search).ask "What changed in Ruby 3.5?"
response.server_tool_calls.map(&:type) # => ["server_tool_use", "web_search_tool_result"]

RubyLLM does not model each tool's result schema. #raw always holds the provider's block exactly as received, and is what RubyLLM replays to the provider in subsequent turns when the wire format requires it.

Constant Summary

Constants included from RubyLLM::Support::Inspectable

RubyLLM::Support::Inspectable::TRUNCATE_AT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from RubyLLM::Support::Inspectable

#full_inspect, #inspect, #pretty_print

Constructor Details

#initialize(type:, raw:, name: nil, id: nil, input: nil, result: nil) ⇒ ServerToolCall

:nodoc:



48
49
50
51
52
53
54
55
# File 'lib/ruby_llm/server_tool_call.rb', line 48

def initialize(type:, raw:, name: nil, id: nil, input: nil, result: nil) # :nodoc:
  @type = type
  @name = name
  @id = id
  @input = input
  @result = result
  @raw = raw
end

Instance Attribute Details

#idObject (readonly)

The provider's identifier for the call, or nil.



28
29
30
# File 'lib/ruby_llm/server_tool_call.rb', line 28

def id
  @id
end

#inputObject (readonly)

The input the model gave the tool (a query, code to run), in the provider's shape, or nil.



32
33
34
# File 'lib/ruby_llm/server_tool_call.rb', line 32

def input
  @input
end

#nameObject (readonly)

The tool name when the provider reports one, such as "web_search", or nil.



25
26
27
# File 'lib/ruby_llm/server_tool_call.rb', line 25

def name
  @name
end

#rawObject (readonly)

The complete provider block as received, used verbatim when the conversation is sent back to the provider.



40
41
42
# File 'lib/ruby_llm/server_tool_call.rb', line 40

def raw
  @raw
end

#resultObject (readonly)

The tool's output in the provider's shape, or nil for blocks that only record the invocation.



36
37
38
# File 'lib/ruby_llm/server_tool_call.rb', line 36

def result
  @result
end

#typeObject (readonly)

The provider's block or item type, such as "server_tool_use", "web_search_tool_result", or "web_search_call".



21
22
23
# File 'lib/ruby_llm/server_tool_call.rb', line 21

def type
  @type
end

Class Method Details

.from_h(data) ⇒ Object

:nodoc:



42
43
44
45
46
# File 'lib/ruby_llm/server_tool_call.rb', line 42

def self.from_h(data) # :nodoc:
  data = Support::Utils.deep_symbolize_keys(data)
  new(type: data[:type], name: data[:name], id: data[:id], input: data[:input],
      result: data[:result], raw: data[:raw])
end

Instance Method Details

#inspect_attributesObject

:nodoc:



69
70
71
# File 'lib/ruby_llm/server_tool_call.rb', line 69

def inspect_attributes # :nodoc:
  { type: type, name: name, id: id, input: input }
end

#to_hObject

Returns the call's attributes as a Hash, omitting nil values.



58
59
60
61
62
63
64
65
66
67
# File 'lib/ruby_llm/server_tool_call.rb', line 58

def to_h
  {
    type: type,
    name: name,
    id: id,
    input: input,
    result: result,
    raw: raw
  }.compact
end