Class: ClaudeSDK::ContentBlock::ToolResult

Inherits:
Object
  • Object
show all
Defined in:
lib/claude_sdk/types.rb

Overview

Tool result content block

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_use_id:, content: nil, is_error: nil) ⇒ ToolResult

Returns a new instance of ToolResult.

Parameters:

  • tool_use_id (String)

    ID of the tool use

  • content (String, Array<Hash>, nil) (defaults to: nil)

    result content

  • is_error (Boolean, nil) (defaults to: nil)

    error flag



173
174
175
176
177
# File 'lib/claude_sdk/types.rb', line 173

def initialize(tool_use_id:, content: nil, is_error: nil)
  @tool_use_id = tool_use_id
  @content = content
  @is_error = is_error
end

Instance Attribute Details

#contentObject

the result content



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/claude_sdk/types.rb', line 167

class ToolResult
  attr_accessor :tool_use_id, :content, :is_error

  # @param tool_use_id [String] ID of the tool use
  # @param content [String, Array<Hash>, nil] result content
  # @param is_error [Boolean, nil] error flag
  def initialize(tool_use_id:, content: nil, is_error: nil)
    @tool_use_id = tool_use_id
    @content = content
    @is_error = is_error
  end

  # @return [Hash] serialized representation
  def to_h
    hash = { type: "tool_result", tool_use_id: tool_use_id }
    hash[:content] = content unless content.nil?
    hash[:is_error] = is_error unless is_error.nil?
    hash
  end
end

#is_errorObject

Returns the value of attribute is_error.



168
169
170
# File 'lib/claude_sdk/types.rb', line 168

def is_error
  @is_error
end

#tool_use_idObject

ID of the corresponding tool use



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/claude_sdk/types.rb', line 167

class ToolResult
  attr_accessor :tool_use_id, :content, :is_error

  # @param tool_use_id [String] ID of the tool use
  # @param content [String, Array<Hash>, nil] result content
  # @param is_error [Boolean, nil] error flag
  def initialize(tool_use_id:, content: nil, is_error: nil)
    @tool_use_id = tool_use_id
    @content = content
    @is_error = is_error
  end

  # @return [Hash] serialized representation
  def to_h
    hash = { type: "tool_result", tool_use_id: tool_use_id }
    hash[:content] = content unless content.nil?
    hash[:is_error] = is_error unless is_error.nil?
    hash
  end
end

Instance Method Details

#to_hHash

Returns serialized representation.

Returns:

  • (Hash)

    serialized representation



180
181
182
183
184
185
# File 'lib/claude_sdk/types.rb', line 180

def to_h
  hash = { type: "tool_result", tool_use_id: tool_use_id }
  hash[:content] = content unless content.nil?
  hash[:is_error] = is_error unless is_error.nil?
  hash
end