Class: LittleGhost::Tool::ExecutionResult

Inherits:
Data
  • Object
show all
Defined in:
lib/little_ghost/tool.rb

Overview

Internal normalized outcome used between Tool, Agent, and code mode.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, content: UNSET_RESULT_VALUE, value: UNSET_RESULT_VALUE, error: nil, artifacts: [], presentation_content: []) ⇒ ExecutionResult

Returns a new instance of ExecutionResult.

Raises:

  • (ArgumentError)


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/little_ghost/tool.rb', line 160

def initialize(
  status:,
  content: UNSET_RESULT_VALUE,
  value: UNSET_RESULT_VALUE,
  error: nil,
  artifacts: [],
  presentation_content: []
)
  if content.equal?(UNSET_RESULT_VALUE) && value.equal?(UNSET_RESULT_VALUE)
    raise ArgumentError, "tool result requires content or value"
  end
  content = value if content.equal?(UNSET_RESULT_VALUE)
  value = content if value.equal?(UNSET_RESULT_VALUE)

  presentations = Array(presentation_content)
  unless presentations.all? do |block|
    block.is_a?(Content::Text) || block.is_a?(Content::Image) || block.is_a?(Content::Document)
  end
    raise ArgumentError, "artifact presentation must contain only text, images, or documents"
  end

  artifact_values = Array(artifacts)
  unless artifact_values.all? { |artifact| artifact.is_a?(Artifact) }
    raise ArgumentError, "artifacts must contain only LittleGhost::Artifact values"
  end

  status = status.to_sym
  raise ArgumentError, "tool result status must be success or error" unless %i[success error].include?(status)

  super(
    value:,
    content:,
    status:,
    error:,
    artifacts: artifact_values.dup.freeze,
    presentation_content: presentations.dup.freeze
  )
end

Instance Attribute Details

#artifactsObject (readonly)

Returns the value of attribute artifacts

Returns:

  • (Object)

    the current value of artifacts



159
160
161
# File 'lib/little_ghost/tool.rb', line 159

def artifacts
  @artifacts
end

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



159
160
161
# File 'lib/little_ghost/tool.rb', line 159

def content
  @content
end

#errorObject (readonly)

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



159
160
161
# File 'lib/little_ghost/tool.rb', line 159

def error
  @error
end

#presentation_contentObject (readonly)

Returns the value of attribute presentation_content

Returns:

  • (Object)

    the current value of presentation_content



159
160
161
# File 'lib/little_ghost/tool.rb', line 159

def presentation_content
  @presentation_content
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



159
160
161
# File 'lib/little_ghost/tool.rb', line 159

def status
  @status
end

#valueObject (readonly)

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



159
160
161
# File 'lib/little_ghost/tool.rb', line 159

def value
  @value
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


203
204
205
# File 'lib/little_ghost/tool.rb', line 203

def error?
  status == :error
end

#success?Boolean

Returns:

  • (Boolean)


199
200
201
# File 'lib/little_ghost/tool.rb', line 199

def success?
  status == :success
end