Class: KairosMcp::Daemon::LlmPhaseFunctions::UsageAccumulator
- Inherits:
-
Object
- Object
- KairosMcp::Daemon::LlmPhaseFunctions::UsageAccumulator
- Defined in:
- lib/kairos_mcp/daemon/llm_phase_functions.rb
Overview
Shared usage tracker across phases within one cycle.
Instance Attribute Summary collapse
-
#input_tokens ⇒ Object
readonly
Returns the value of attribute input_tokens.
-
#llm_calls ⇒ Object
readonly
Returns the value of attribute llm_calls.
-
#output_tokens ⇒ Object
readonly
Returns the value of attribute output_tokens.
Instance Method Summary collapse
-
#initialize ⇒ UsageAccumulator
constructor
A new instance of UsageAccumulator.
-
#record(response) ⇒ Object
Record LLM usage from a response.
- #reset! ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ UsageAccumulator
Returns a new instance of UsageAccumulator.
24 25 26 27 28 |
# File 'lib/kairos_mcp/daemon/llm_phase_functions.rb', line 24 def initialize @llm_calls = 0 @input_tokens = 0 @output_tokens = 0 end |
Instance Attribute Details
#input_tokens ⇒ Object (readonly)
Returns the value of attribute input_tokens.
22 23 24 |
# File 'lib/kairos_mcp/daemon/llm_phase_functions.rb', line 22 def input_tokens @input_tokens end |
#llm_calls ⇒ Object (readonly)
Returns the value of attribute llm_calls.
22 23 24 |
# File 'lib/kairos_mcp/daemon/llm_phase_functions.rb', line 22 def llm_calls @llm_calls end |
#output_tokens ⇒ Object (readonly)
Returns the value of attribute output_tokens.
22 23 24 |
# File 'lib/kairos_mcp/daemon/llm_phase_functions.rb', line 22 def output_tokens @output_tokens end |
Instance Method Details
#record(response) ⇒ Object
Record LLM usage from a response. When DaemonLlmCaller returns ‘attempts: N` (including retries), llm_calls is incremented by N. Callers without `attempts` default to 1.
33 34 35 36 37 |
# File 'lib/kairos_mcp/daemon/llm_phase_functions.rb', line 33 def record(response) @llm_calls += Integer(response[:attempts] || response['attempts'] || 1) @input_tokens += Integer(response[:input_tokens] || response['input_tokens'] || 0) @output_tokens += Integer(response[:output_tokens] || response['output_tokens'] || 0) end |
#reset! ⇒ Object
43 44 45 46 47 |
# File 'lib/kairos_mcp/daemon/llm_phase_functions.rb', line 43 def reset! @llm_calls = 0 @input_tokens = 0 @output_tokens = 0 end |
#to_h ⇒ Object
39 40 41 |
# File 'lib/kairos_mcp/daemon/llm_phase_functions.rb', line 39 def to_h { llm_calls: @llm_calls, input_tokens: @input_tokens, output_tokens: @output_tokens } end |