Class: Events::ToolResponse

Inherits:
Base
  • Object
show all
Defined in:
lib/events/tool_response.rb

Constant Summary collapse

TYPE =
"tool_response"

Instance Attribute Summary collapse

Attributes inherited from Base

#content, #session_id, #timestamp

Instance Method Summary collapse

Methods inherited from Base

#event_name

Constructor Details

#initialize(content:, tool_name:, success: true, tool_use_id: nil, session_id: nil) ⇒ ToolResponse

Returns a new instance of ToolResponse.

Parameters:

  • content (String)

    tool execution output

  • tool_name (String)

    registered tool name

  • success (Boolean) (defaults to: true)

    whether the tool executed successfully

  • tool_use_id (String, nil) (defaults to: nil)

    Anthropic-assigned ID for correlating call/result

  • session_id (String, nil) (defaults to: nil)

    optional session identifier



14
15
16
17
18
19
# File 'lib/events/tool_response.rb', line 14

def initialize(content:, tool_name:, success: true, tool_use_id: nil, session_id: nil)
  super(content: content, session_id: session_id)
  @tool_name = tool_name
  @success = success
  @tool_use_id = tool_use_id
end

Instance Attribute Details

#successObject (readonly)

Returns the value of attribute success.



7
8
9
# File 'lib/events/tool_response.rb', line 7

def success
  @success
end

#tool_nameObject (readonly)

Returns the value of attribute tool_name.



7
8
9
# File 'lib/events/tool_response.rb', line 7

def tool_name
  @tool_name
end

#tool_use_idObject (readonly)

Returns the value of attribute tool_use_id.



7
8
9
# File 'lib/events/tool_response.rb', line 7

def tool_use_id
  @tool_use_id
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/events/tool_response.rb', line 25

def success?
  @success
end

#to_hObject



29
30
31
# File 'lib/events/tool_response.rb', line 29

def to_h
  super.merge(tool_name: tool_name, success: success, tool_use_id: tool_use_id)
end

#typeObject



21
22
23
# File 'lib/events/tool_response.rb', line 21

def type
  TYPE
end