Class: Smith::Workflow::Composite::Effects

Inherits:
Payload
  • Object
show all
Defined in:
lib/smith/workflow/composite/effects.rb

Overview

Length is fail-closed value validation, not logic: every key the contract admits gets a bounded value check beside the contract that admits it. Splitting the checks away from the payload they guard would trade cohesion for a metric.

Constant Summary

Constants inherited from Payload

Payload::MAX_SERIALIZED_BYTES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Effects

Returns a new instance of Effects.



38
39
40
41
42
43
44
45
46
47
# File 'lib/smith/workflow/composite/effects.rb', line 38

def initialize(attributes)
  owned = self.class.normalize_attributes(attributes)
  normalized = MessageValueNormalizer.new(owned, label: "composite effects").call
  usage_entries, tool_results, budget_consumed =
    normalized.values_at("usage_entries", "tool_results", "budget_consumed")
  @total_tokens, @total_cost = validate_usage_entries!(usage_entries)
  validate_tool_results!(tool_results)
  validate_budget!(budget_consumed)
  super(usage_entries:, tool_results:, budget_consumed:)
end

Instance Attribute Details

#total_costObject (readonly)

rubocop:disable Metrics/ClassLength



18
19
20
# File 'lib/smith/workflow/composite/effects.rb', line 18

def total_cost
  @total_cost
end

#total_tokensObject (readonly)

rubocop:disable Metrics/ClassLength



18
19
20
# File 'lib/smith/workflow/composite/effects.rb', line 18

def total_tokens
  @total_tokens
end