Class: KairosMcp::Daemon::LlmPhaseFunctions::UsageAccumulator

Inherits:
Object
  • Object
show all
Defined in:
lib/kairos_mcp/daemon/llm_phase_functions.rb

Overview

Shared usage tracker across phases within one cycle.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUsageAccumulator

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_tokensObject (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_callsObject (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_tokensObject (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_hObject



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