Class: SwarmSDK::Hooks::ToolResult

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/hooks/tool_result.rb

Overview

Represents the result of a tool execution

This is a simple value object that wraps tool execution results in a consistent format for post-tool-use hooks.

Examples:

Access tool result in a hook

swarm.add_callback(:post_tool_use) do |context|
  if context.tool_result.success?
    puts "Tool succeeded: #{context.tool_result.content}"
  else
    puts "Tool failed: #{context.tool_result.error}"
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tool_call_id:, tool_name:, content: nil, success: true, error: nil) ⇒ ToolResult



26
27
28
29
30
31
32
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 26

def initialize(tool_call_id:, tool_name:, content: nil, success: true, error: nil)
  @tool_call_id = tool_call_id
  @tool_name = tool_name
  @content = content
  @success = success
  @error = error
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



19
20
21
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 19

def content
  @content
end

#errorObject (readonly)

Returns the value of attribute error.



19
20
21
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 19

def error
  @error
end

#successObject (readonly)

Returns the value of attribute success.



19
20
21
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 19

def success
  @success
end

#tool_call_idObject (readonly)

Returns the value of attribute tool_call_id.



19
20
21
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 19

def tool_call_id
  @tool_call_id
end

#tool_nameObject (readonly)

Returns the value of attribute tool_name.



19
20
21
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 19

def tool_name
  @tool_name
end

Instance Method Details

#failure?Boolean

Check if the tool execution failed



44
45
46
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 44

def failure?
  !@success
end

#success?Boolean

Check if the tool execution succeeded



37
38
39
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 37

def success?
  @success
end

#to_hHash

Convert to hash representation



51
52
53
54
55
56
57
58
59
# File 'lib/swarm_sdk/hooks/tool_result.rb', line 51

def to_h
  {
    tool_call_id: @tool_call_id,
    tool_name: @tool_name,
    content: @content,
    success: @success,
    error: @error,
  }
end