Class: LittleGhost::Tool::ExecutionResult
- Inherits:
-
Data
- Object
- Data
- LittleGhost::Tool::ExecutionResult
- Defined in:
- lib/little_ghost/tool.rb
Overview
Internal normalized outcome used between Tool, Agent, and code mode.
Instance Attribute Summary collapse
-
#artifacts ⇒ Object
readonly
Returns the value of attribute artifacts.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#presentation_content ⇒ Object
readonly
Returns the value of attribute presentation_content.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(status:, content: UNSET_RESULT_VALUE, value: UNSET_RESULT_VALUE, error: nil, artifacts: [], presentation_content: []) ⇒ ExecutionResult
constructor
A new instance of ExecutionResult.
- #success? ⇒ Boolean
Constructor Details
#initialize(status:, content: UNSET_RESULT_VALUE, value: UNSET_RESULT_VALUE, error: nil, artifacts: [], presentation_content: []) ⇒ ExecutionResult
Returns a new instance of ExecutionResult.
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
#artifacts ⇒ Object (readonly)
Returns the value of attribute artifacts
159 160 161 |
# File 'lib/little_ghost/tool.rb', line 159 def artifacts @artifacts end |
#content ⇒ Object (readonly)
Returns the value of attribute content
159 160 161 |
# File 'lib/little_ghost/tool.rb', line 159 def content @content end |
#error ⇒ Object (readonly)
Returns the value of attribute error
159 160 161 |
# File 'lib/little_ghost/tool.rb', line 159 def error @error end |
#presentation_content ⇒ Object (readonly)
Returns the value of attribute presentation_content
159 160 161 |
# File 'lib/little_ghost/tool.rb', line 159 def presentation_content @presentation_content end |
#status ⇒ Object (readonly)
Returns the value of attribute status
159 160 161 |
# File 'lib/little_ghost/tool.rb', line 159 def status @status end |
#value ⇒ Object (readonly)
Returns the value of attribute value
159 160 161 |
# File 'lib/little_ghost/tool.rb', line 159 def value @value end |
Instance Method Details
#error? ⇒ Boolean
203 204 205 |
# File 'lib/little_ghost/tool.rb', line 203 def error? status == :error end |
#success? ⇒ Boolean
199 200 201 |
# File 'lib/little_ghost/tool.rb', line 199 def success? status == :success end |