Class: RubyPi::LLM::ToolCall
- Inherits:
-
Object
- Object
- RubyPi::LLM::ToolCall
- Defined in:
- lib/ruby_pi/llm/tool_call.rb
Overview
A tool call extracted from an LLM response. Contains the unique call ID, the function name, and the parsed arguments hash. Provider-specific formats are normalized into this common structure.
Instance Attribute Summary collapse
-
#arguments ⇒ Hash
readonly
The parsed arguments to pass to the tool.
-
#id ⇒ String
readonly
Unique identifier for this tool call, used to match results back to the calling context.
-
#name ⇒ String
readonly
The name of the tool/function to invoke.
Instance Method Summary collapse
-
#initialize(id:, name:, arguments: {}) ⇒ ToolCall
constructor
Creates a new ToolCall instance.
-
#to_h ⇒ Hash
Returns a hash representation of the tool call for serialization.
-
#to_s ⇒ String
(also: #inspect)
Returns a human-readable string representation of the tool call.
Constructor Details
#initialize(id:, name:, arguments: {}) ⇒ ToolCall
Creates a new ToolCall instance.
36 37 38 39 40 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 36 def initialize(id:, name:, arguments: {}) @id = id @name = name @arguments = arguments.is_a?(Hash) ? arguments : parse_arguments(arguments) end |
Instance Attribute Details
#arguments ⇒ Hash (readonly)
Returns the parsed arguments to pass to the tool.
29 30 31 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 29 def arguments @arguments end |
#id ⇒ String (readonly)
Returns unique identifier for this tool call, used to match results back to the calling context.
23 24 25 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 23 def id @id end |
#name ⇒ String (readonly)
Returns the name of the tool/function to invoke.
26 27 28 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 26 def name @name end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the tool call for serialization.
45 46 47 48 49 50 51 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 45 def to_h { id: @id, name: @name, arguments: @arguments } end |
#to_s ⇒ String Also known as: inspect
Returns a human-readable string representation of the tool call.
56 57 58 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 56 def to_s "#<RubyPi::LLM::ToolCall id=#{@id.inspect} name=#{@name.inspect} arguments=#{@arguments.inspect}>" end |