Class: Crimson::Message::ToolResult

Inherits:
Base
  • Object
show all
Defined in:
lib/crimson/message.rb

Overview

The result of executing a tool call, sent back to the model.

Instance Attribute Summary collapse

Attributes inherited from Base

#role

Instance Method Summary collapse

Constructor Details

#initialize(tool_call_id:, name:, content:) ⇒ ToolResult

Returns a new instance of ToolResult.

Parameters:

  • tool_call_id (String)
  • name (String)
  • content (String)


146
147
148
149
150
151
# File 'lib/crimson/message.rb', line 146

def initialize(tool_call_id:, name:, content:)
  super("tool")
  @tool_call_id = tool_call_id
  @name = name
  @content = content
end

Instance Attribute Details

#contentString (readonly)

Returns:

  • (String)

    the ID of the tool call this result belongs to

  • (String)

    the tool name

  • (String)

    the result content



141
142
143
# File 'lib/crimson/message.rb', line 141

def content
  @content
end

#nameString (readonly)

Returns:

  • (String)

    the ID of the tool call this result belongs to

  • (String)

    the tool name

  • (String)

    the result content



141
142
143
# File 'lib/crimson/message.rb', line 141

def name
  @name
end

#tool_call_idString (readonly)

Returns:

  • (String)

    the ID of the tool call this result belongs to

  • (String)

    the tool name

  • (String)

    the result content



141
142
143
# File 'lib/crimson/message.rb', line 141

def tool_call_id
  @tool_call_id
end

Instance Method Details

#to_anthropic_hHash

Returns Anthropic-compatible representation.

Returns:

  • (Hash)

    Anthropic-compatible representation



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/crimson/message.rb', line 163

def to_anthropic_h
  {
    role: "user",
    content: [
      {
        type: "tool_result",
        tool_use_id: @tool_call_id,
        content: @content
      }
    ]
  }
end

#to_openai_hHash

Returns OpenAI-compatible representation.

Returns:

  • (Hash)

    OpenAI-compatible representation



154
155
156
157
158
159
160
# File 'lib/crimson/message.rb', line 154

def to_openai_h
  {
    role: "tool",
    tool_call_id: @tool_call_id,
    content: @content
  }
end