Module: Legion::Extensions::Agentic::Inference::BeliefRevision::Runners::BeliefRevision
- Includes:
- Helpers::Constants, Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb
Constant Summary
Helpers::Constants::BELIEF_STATES, Helpers::Constants::CONTRADICTION_THRESHOLD, Helpers::Constants::CREDENCE_CEILING, Helpers::Constants::CREDENCE_FLOOR, Helpers::Constants::CREDENCE_LABELS, Helpers::Constants::DECAY_RATE, Helpers::Constants::DEFAULT_CREDENCE, Helpers::Constants::ENTRENCHMENT_ALPHA, Helpers::Constants::EVIDENCE_TYPES, Helpers::Constants::EVIDENCE_WEIGHT, Helpers::Constants::LINK_TYPES, Helpers::Constants::MAX_BELIEFS, Helpers::Constants::MAX_EVIDENCE_PER_BELIEF, Helpers::Constants::MAX_HISTORY, Helpers::Constants::MAX_LINKS, Helpers::Constants::STATE_THRESHOLDS
Instance Method Summary
collapse
-
#add_belief(proposition:, domain: :general, credence: DEFAULT_CREDENCE) ⇒ Object
-
#belief_revision_stats ⇒ Object
-
#belief_status(belief_id:) ⇒ Object
-
#beliefs_in_domain(domain:) ⇒ Object
-
#coherence_report ⇒ Object
-
#find_contradictions ⇒ Object
-
#link_beliefs(from_id:, to_id:, link_type:) ⇒ Object
-
#revise_belief(belief_id:, new_credence:) ⇒ Object
-
#submit_evidence(belief_id:, evidence_type:, content:, direction: :support, weight: EVIDENCE_WEIGHT, source: :unknown) ⇒ Object
-
#update_belief_revision ⇒ Object
Instance Method Details
#add_belief(proposition:, domain: :general, credence: DEFAULT_CREDENCE) ⇒ Object
13
14
15
16
17
18
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 13
def add_belief(proposition:, domain: :general, credence: DEFAULT_CREDENCE, **)
belief = network.add_belief(proposition: proposition, domain: domain, credence: credence)
return { success: false, reason: :limit_reached } unless belief
{ success: true, belief_id: belief.id, credence: belief.credence.round(4) }
end
|
#belief_revision_stats ⇒ Object
74
75
76
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 74
def belief_revision_stats(**)
{ success: true }.merge(network.to_h)
end
|
#belief_status(belief_id:) ⇒ Object
46
47
48
49
50
51
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 46
def belief_status(belief_id:, **)
belief = network.beliefs[belief_id]
return { success: false, reason: :not_found } unless belief
{ success: true }.merge(belief.to_h)
end
|
#beliefs_in_domain(domain:) ⇒ Object
58
59
60
61
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 58
def beliefs_in_domain(domain:, **)
beliefs = network.beliefs_in(domain: domain)
{ success: true, beliefs: beliefs, count: beliefs.size }
end
|
#coherence_report ⇒ Object
63
64
65
66
67
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 63
def coherence_report(**)
{ success: true, coherence: network.coherence_score.round(4),
believed: network.believed.size, disbelieved: network.disbelieved.size,
entrenched: network.entrenched.size, contradictions: network.contradictions.size }
end
|
#find_contradictions ⇒ Object
53
54
55
56
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 53
def find_contradictions(**)
pairs = network.contradictions
{ success: true, contradictions: pairs, count: pairs.size }
end
|
#link_beliefs(from_id:, to_id:, link_type:) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 32
def link_beliefs(from_id:, to_id:, link_type:, **)
result = network.link_beliefs(from_id: from_id, to_id: to_id, link_type: link_type)
return { success: false, reason: :invalid_or_limit } unless result
{ success: true, from: from_id, to: to_id, link_type: link_type }
end
|
#revise_belief(belief_id:, new_credence:) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 39
def revise_belief(belief_id:, new_credence:, **)
belief = network.revise_belief(belief_id: belief_id, new_credence: new_credence)
return { success: false, reason: :not_found } unless belief
{ success: true, belief_id: belief_id, credence: belief.credence.round(4), state: belief.state }
end
|
#submit_evidence(belief_id:, evidence_type:, content:, direction: :support, weight: EVIDENCE_WEIGHT, source: :unknown) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 20
def submit_evidence(belief_id:, evidence_type:, content:, direction: :support,
weight: EVIDENCE_WEIGHT, source: :unknown, **)
ev = network.add_evidence(
belief_id: belief_id, evidence_type: evidence_type, content: content,
direction: direction, weight: weight, source: source
)
return { success: false, reason: :not_found_or_full } unless ev
belief = network.beliefs[belief_id]
{ success: true, evidence_id: ev.id, belief_credence: belief.credence.round(4) }
end
|
#update_belief_revision ⇒ Object
69
70
71
72
|
# File 'lib/legion/extensions/agentic/inference/belief_revision/runners/belief_revision.rb', line 69
def update_belief_revision(**)
network.decay_all
{ success: true }.merge(network.to_h)
end
|