Class: Smith::Workflow::AgentResult

Inherits:
Struct
  • Object
show all
Defined in:
lib/smith/workflow.rb

Overview

keyword_init: true so adding new fields in future schema versions remains backward-compatible: ‘from_response` and `from_h` can fill extra fields without breaking existing call sites that pass the historical positional args. Reading old persisted records into a newer Struct shape: from_h slices to current members (unknown keys silently dropped; missing keys default to nil).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#contentObject

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



79
80
81
# File 'lib/smith/workflow.rb', line 79

def content
  @content
end

#costObject

Returns the value of attribute cost

Returns:

  • (Object)

    the current value of cost



79
80
81
# File 'lib/smith/workflow.rb', line 79

def cost
  @cost
end

#input_tokensObject

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



79
80
81
# File 'lib/smith/workflow.rb', line 79

def input_tokens
  @input_tokens
end

#model_usedObject

Returns the value of attribute model_used

Returns:

  • (Object)

    the current value of model_used



79
80
81
# File 'lib/smith/workflow.rb', line 79

def model_used
  @model_used
end

#output_tokensObject

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



79
80
81
# File 'lib/smith/workflow.rb', line 79

def output_tokens
  @output_tokens
end

Class Method Details

.from_response(response, content, model_used: nil) ⇒ Object



83
84
85
86
87
88
89
90
91
# File 'lib/smith/workflow.rb', line 83

def self.from_response(response, content, model_used: nil)
  new(
    content: content,
    input_tokens: response.respond_to?(:input_tokens) ? response.input_tokens : nil,
    output_tokens: response.respond_to?(:output_tokens) ? response.output_tokens : nil,
    cost: nil,
    model_used: model_used
  )
end

Instance Method Details

#usage_known?Boolean

Returns:

  • (Boolean)


93
94
95
# File 'lib/smith/workflow.rb', line 93

def usage_known?
  !input_tokens.nil? && !output_tokens.nil?
end