Class: Smith::Workflow::UsageEntry
- Inherits:
-
Struct
- Object
- Struct
- Smith::Workflow::UsageEntry
- Defined in:
- lib/smith/workflow/usage_entry.rb
Overview
One row per provider RESPONSE within an agent provider attempt.
usage_id is a UUID generated at recording time and stable across
persist/restore so hosts can use it as an idempotency anchor.
transition, branch_key, round, and workflow come from the
ambient Smith::Attribution at recording time, so hosts can attribute
usage to the exact step, fan-out branch, optimizer round, and (for
nested workflows) the exact graph that spent it.
attempt_id is shared by every entry the same provider attempt
produced (an attempt with an N-round tool loop records N entries):
join on it against the :provider_call trace event for the attempt's
single measured duration; never sum a duration across entries. Every
attempt emits its :provider_call (an attempt aborted by a
non-provider error emits with outcome: :aborted before re-raising),
so prefix-accounted entries always have their join target.
All optional members are nil on entries restored from checkpoints written by
earlier Smith versions, and nil attribution members are omitted from
serialization so those documents re-serialize byte-identically.
rubocop:disable Style/RedundantStructKeywordInit
Instance Attribute Summary collapse
-
#agent_name ⇒ Object
Returns the value of attribute agent_name.
-
#attempt_id ⇒ Object
Returns the value of attribute attempt_id.
-
#attempt_kind ⇒ Object
Returns the value of attribute attempt_kind.
-
#branch_key ⇒ Object
Returns the value of attribute branch_key.
-
#cost ⇒ Object
Returns the value of attribute cost.
-
#input_tokens ⇒ Object
Returns the value of attribute input_tokens.
-
#model ⇒ Object
Returns the value of attribute model.
-
#output_tokens ⇒ Object
Returns the value of attribute output_tokens.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#recorded_at ⇒ Object
Returns the value of attribute recorded_at.
-
#round ⇒ Object
Returns the value of attribute round.
-
#transition ⇒ Object
Returns the value of attribute transition.
-
#usage_id ⇒ Object
Returns the value of attribute usage_id.
-
#workflow ⇒ Object
Returns the value of attribute workflow.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(**attributes) ⇒ UsageEntry
constructor
A new instance of UsageEntry.
-
#to_h ⇒ Object
Serialization is additive only when present: nil attribution members are omitted so an entry restored from a pre-attribution checkpoint re-serializes byte-identically.
Constructor Details
#initialize(**attributes) ⇒ UsageEntry
Returns a new instance of UsageEntry.
41 42 43 44 45 46 47 |
# File 'lib/smith/workflow/usage_entry.rb', line 41 def initialize(**attributes) attributes = attributes.transform_values do |value| value.is_a?(String) ? value.dup.freeze : value end super(**attributes) # rubocop:disable Style/SuperArguments freeze end |
Instance Attribute Details
#agent_name ⇒ Object
Returns the value of attribute agent_name
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def agent_name @agent_name end |
#attempt_id ⇒ Object
Returns the value of attribute attempt_id
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def attempt_id @attempt_id end |
#attempt_kind ⇒ Object
Returns the value of attribute attempt_kind
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def attempt_kind @attempt_kind end |
#branch_key ⇒ Object
Returns the value of attribute branch_key
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def branch_key @branch_key end |
#cost ⇒ Object
Returns the value of attribute cost
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def cost @cost end |
#input_tokens ⇒ Object
Returns the value of attribute input_tokens
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def input_tokens @input_tokens end |
#model ⇒ Object
Returns the value of attribute model
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def model @model end |
#output_tokens ⇒ Object
Returns the value of attribute output_tokens
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def output_tokens @output_tokens end |
#provider ⇒ Object
Returns the value of attribute provider
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def provider @provider end |
#recorded_at ⇒ Object
Returns the value of attribute recorded_at
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def recorded_at @recorded_at end |
#round ⇒ Object
Returns the value of attribute round
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def round @round end |
#transition ⇒ Object
Returns the value of attribute transition
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def transition @transition end |
#usage_id ⇒ Object
Returns the value of attribute usage_id
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def usage_id @usage_id end |
#workflow ⇒ Object
Returns the value of attribute workflow
24 25 26 |
# File 'lib/smith/workflow/usage_entry.rb', line 24 def workflow @workflow end |
Class Method Details
.from_h(hash) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/smith/workflow/usage_entry.rb', line 57 def self.from_h(hash) sym = hash.transform_keys(&:to_sym) filtered = sym.slice(*members) %i[agent_name provider attempt_kind transition branch_key].each do |attribute| filtered[attribute] = filtered[attribute].to_sym if filtered[attribute].is_a?(String) end new(**filtered) end |
Instance Method Details
#to_h ⇒ Object
Serialization is additive only when present: nil attribution members are omitted so an entry restored from a pre-attribution checkpoint re-serializes byte-identically. Hosts that digest whole persisted documents (exact-mutation proofs) depend on this stability.
53 54 55 |
# File 'lib/smith/workflow/usage_entry.rb', line 53 def to_h super.reject { |key, value| value.nil? && %i[transition branch_key round attempt_id workflow].include?(key) } end |