Class: RubyLLM::ToolCall
- Inherits:
-
Object
- Object
- RubyLLM::ToolCall
- Includes:
- Support::Inspectable
- Defined in:
- lib/ruby_llm/tool_call.rb
Overview
A ToolCall is a request to run a tool with specific arguments. Instances
appear in Message#tool_calls. Local calls are yielded to tool callbacks
such as Chat#before_tool_call. Remote calls awaiting approval return
true from #remote? and appear in Chat#pending_approvals.
chat.before_tool_call do |tool_call|
puts "Calling tool: #{tool_call.name}"
puts "Arguments: #{tool_call.arguments}"
end
Constant Summary
Constants included from Support::Inspectable
Support::Inspectable::TRUNCATE_AT
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
The arguments the model supplied for the invocation, as a Hash.
-
#id ⇒ Object
readonly
The unique identifier for this call.
-
#name ⇒ Object
readonly
The name of the tool the model wants to invoke.
-
#thought_signature ⇒ Object
The Gemini thought signature attached to this call, or
nil.
Instance Method Summary collapse
-
#initialize(id:, name:, arguments: {}, thought_signature: nil, remote: false) ⇒ ToolCall
constructor
:nodoc:.
-
#inspect_attributes ⇒ Object
:nodoc:.
-
#remote? ⇒ Boolean
Returns
trueif the provider executes this call after approval. -
#to_h ⇒ Object
Returns the call as a Hash, omitting
nilvalues.
Methods included from Support::Inspectable
#full_inspect, #inspect, #pretty_print
Constructor Details
#initialize(id:, name:, arguments: {}, thought_signature: nil, remote: false) ⇒ ToolCall
:nodoc:
35 36 37 38 39 40 41 |
# File 'lib/ruby_llm/tool_call.rb', line 35 def initialize(id:, name:, arguments: {}, thought_signature: nil, remote: false) # :nodoc: @id = id @name = name @arguments = arguments @thought_signature = thought_signature @remote = remote end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
The arguments the model supplied for the invocation, as a Hash.
25 26 27 |
# File 'lib/ruby_llm/tool_call.rb', line 25 def arguments @arguments end |
#id ⇒ Object (readonly)
The unique identifier for this call. The tool result message answering this call carries the same id.
19 20 21 |
# File 'lib/ruby_llm/tool_call.rb', line 19 def id @id end |
#name ⇒ Object (readonly)
The name of the tool the model wants to invoke.
22 23 24 |
# File 'lib/ruby_llm/tool_call.rb', line 22 def name @name end |
#thought_signature ⇒ Object
The Gemini thought signature attached to this call, or nil.
RubyLLM replays it to the provider on later requests.
33 34 35 |
# File 'lib/ruby_llm/tool_call.rb', line 33 def thought_signature @thought_signature end |
Instance Method Details
#inspect_attributes ⇒ Object
:nodoc:
43 44 45 |
# File 'lib/ruby_llm/tool_call.rb', line 43 def inspect_attributes # :nodoc: { id: id, name: name, arguments: arguments, remote: remote? || nil }.compact end |
#remote? ⇒ Boolean
Returns true if the provider executes this call after approval.
Local tools executed by the application return false.
29 |
# File 'lib/ruby_llm/tool_call.rb', line 29 def remote? = @remote |
#to_h ⇒ Object
Returns the call as a Hash, omitting nil values.
48 49 50 51 52 53 54 55 56 |
# File 'lib/ruby_llm/tool_call.rb', line 48 def to_h { id: @id, name: @name, arguments: @arguments, remote: remote? || nil, thought_signature: @thought_signature }.compact end |