Class: Legion::Extensions::Agentic::Inference::Debugging::Helpers::CausalTrace

Inherits:
Object
  • Object
show all
Defined in:
lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_id:, root_cause:, confidence:) ⇒ CausalTrace

Returns a new instance of CausalTrace.



14
15
16
17
18
19
20
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 14

def initialize(error_id:, root_cause:, confidence:)
  @id         = SecureRandom.uuid
  @error_id   = error_id
  @root_cause = root_cause
  @confidence = confidence.clamp(0.0, 1.0).round(10)
  @steps      = []
end

Instance Attribute Details

#confidenceObject (readonly)

Returns the value of attribute confidence.



12
13
14
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 12

def confidence
  @confidence
end

#error_idObject (readonly)

Returns the value of attribute error_id.



12
13
14
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 12

def error_id
  @error_id
end

#idObject (readonly)

Returns the value of attribute id.



12
13
14
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 12

def id
  @id
end

#root_causeObject (readonly)

Returns the value of attribute root_cause.



12
13
14
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 12

def root_cause
  @root_cause
end

#stepsObject (readonly)

Returns the value of attribute steps.



12
13
14
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 12

def steps
  @steps
end

Instance Method Details

#add_step!(phase:, description:) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 22

def add_step!(phase:, description:)
  @steps << {
    phase:       phase,
    description: description,
    timestamp:   Time.now.utc
  }
  self
end

#depthObject



31
32
33
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 31

def depth
  @steps.size
end

#to_hObject



35
36
37
38
39
40
41
42
43
44
# File 'lib/legion/extensions/agentic/inference/debugging/helpers/causal_trace.rb', line 35

def to_h
  {
    id:         @id,
    error_id:   @error_id,
    steps:      @steps.map(&:dup),
    root_cause: @root_cause,
    confidence: @confidence,
    depth:      depth
  }
end