Class: Legion::Extensions::Agentic::Inference::Schema::Helpers::CausalRelation

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cause:, effect:, relation_type:, confidence: 0.5) ⇒ CausalRelation

Returns a new instance of CausalRelation.



15
16
17
18
19
20
21
22
23
24
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 15

def initialize(cause:, effect:, relation_type:, confidence: 0.5)
  @id             = SecureRandom.uuid
  @cause          = cause
  @effect         = effect
  @relation_type  = relation_type
  @confidence     = confidence.clamp(0.0, 1.0)
  @evidence_count = 1
  @created_at     = Time.now.utc
  @updated_at     = Time.now.utc
end

Instance Attribute Details

#causeObject (readonly)

Returns the value of attribute cause.



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

def cause
  @cause
end

#confidenceObject (readonly)

Returns the value of attribute confidence.



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

def confidence
  @confidence
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#effectObject (readonly)

Returns the value of attribute effect.



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

def effect
  @effect
end

#evidence_countObject (readonly)

Returns the value of attribute evidence_count.



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

def evidence_count
  @evidence_count
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#relation_typeObject (readonly)

Returns the value of attribute relation_type.



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

def relation_type
  @relation_type
end

#updated_atObject (readonly)

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

Instance Method Details

#decayObject



37
38
39
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 37

def decay
  @confidence = [@confidence - Constants::DECAY_RATE, 0.0].max
end

#established?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 41

def established?
  @confidence >= Constants::CONFIDENCE_LEVELS[:established]
end

#prunable?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 49

def prunable?
  @confidence < Constants::PRUNE_THRESHOLD
end

#reinforce(amount = Constants::REINFORCEMENT_BONUS) ⇒ Object



26
27
28
29
30
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 26

def reinforce(amount = Constants::REINFORCEMENT_BONUS)
  @confidence = [@confidence + amount, 1.0].min
  @evidence_count += 1
  @updated_at = Time.now.utc
end

#speculative?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 45

def speculative?
  @confidence <= Constants::CONFIDENCE_LEVELS[:speculative]
end

#to_hObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 53

def to_h
  {
    id:             @id,
    cause:          @cause,
    effect:         @effect,
    relation_type:  @relation_type,
    confidence:     @confidence.round(4),
    evidence_count: @evidence_count,
    established:    established?
  }
end

#weaken(amount = Constants::CONTRADICTION_PENALTY) ⇒ Object



32
33
34
35
# File 'lib/legion/extensions/agentic/inference/schema/helpers/causal_relation.rb', line 32

def weaken(amount = Constants::CONTRADICTION_PENALTY)
  @confidence = [@confidence - amount, 0.0].max
  @updated_at = Time.now.utc
end