Class: ActiveAgent::Delegation::Ledger
- Inherits:
-
Object
- Object
- ActiveAgent::Delegation::Ledger
- Defined in:
- lib/active_agent/delegation/ledger.rb
Overview
Running tally of what delegated work has consumed.
One ledger is kept per delegation plus one for the agent as a whole, and both live on the agent instance — which is created fresh for every generation. A budget is therefore scoped to a single generation and its entire tool loop, with no cross-request bleed and nothing to reset.
Instance Attribute Summary collapse
-
#calls ⇒ Integer
readonly
Delegated calls completed.
-
#cost ⇒ Float
readonly
Cumulative USD spend (0.0 when no rates are known).
-
#duration ⇒ Float
readonly
Cumulative wall-clock seconds.
-
#tokens ⇒ Integer
readonly
Cumulative total tokens.
Instance Method Summary collapse
-
#initialize ⇒ Ledger
constructor
A new instance of Ledger.
-
#record(tokens: 0, cost: nil, duration: 0.0) ⇒ self
Records one delegated call.
- #to_h ⇒ Hash
Constructor Details
#initialize ⇒ Ledger
Returns a new instance of Ledger.
28 29 30 31 32 33 |
# File 'lib/active_agent/delegation/ledger.rb', line 28 def initialize @calls = 0 @tokens = 0 @cost = 0.0 @duration = 0.0 end |
Instance Attribute Details
#calls ⇒ Integer (readonly)
Returns delegated calls completed.
20 21 22 |
# File 'lib/active_agent/delegation/ledger.rb', line 20 def calls @calls end |
#cost ⇒ Float (readonly)
Returns cumulative USD spend (0.0 when no rates are known).
24 25 26 |
# File 'lib/active_agent/delegation/ledger.rb', line 24 def cost @cost end |
#duration ⇒ Float (readonly)
Returns cumulative wall-clock seconds.
26 27 28 |
# File 'lib/active_agent/delegation/ledger.rb', line 26 def duration @duration end |
#tokens ⇒ Integer (readonly)
Returns cumulative total tokens.
22 23 24 |
# File 'lib/active_agent/delegation/ledger.rb', line 22 def tokens @tokens end |
Instance Method Details
#record(tokens: 0, cost: nil, duration: 0.0) ⇒ self
Records one delegated call.
41 42 43 44 45 46 47 48 |
# File 'lib/active_agent/delegation/ledger.rb', line 41 def record(tokens: 0, cost: nil, duration: 0.0) @calls += 1 @tokens += tokens.to_i @cost += cost.to_f @duration += duration.to_f self end |
#to_h ⇒ Hash
51 52 53 |
# File 'lib/active_agent/delegation/ledger.rb', line 51 def to_h { calls: calls, tokens: tokens, cost: cost, duration: duration } end |