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.
38 39 40 41 42 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 38 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.
31 32 33 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 31 def arguments @arguments end |
#id ⇒ String (readonly)
Returns unique identifier for this tool call, used to match results back to the calling context.
25 26 27 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 25 def id @id end |
#name ⇒ String (readonly)
Returns the name of the tool/function to invoke.
28 29 30 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 28 def name @name end |
Instance Method Details
#to_h ⇒ Hash
Returns a hash representation of the tool call for serialization.
47 48 49 50 51 52 53 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 47 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.
58 59 60 |
# File 'lib/ruby_pi/llm/tool_call.rb', line 58 def to_s "#<RubyPi::LLM::ToolCall id=#{@id.inspect} name=#{@name.inspect} arguments=#{@arguments.inspect}>" end |