Module: Legion::Extensions::Agentic::Inference::HypothesisTesting::Runners::HypothesisTesting

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb

Instance Method Summary collapse

Instance Method Details

#competing_hypotheses(domain:) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb', line 71

def competing_hypotheses(domain:, **)
  hypotheses = hypothesis_engine.competing_hypotheses(domain: domain)
  log.debug "[hypothesis_testing] competing count=#{hypotheses.size} domain=#{domain}"
  {
    domain:     domain,
    count:      hypotheses.size,
    hypotheses: hypotheses.map(&:to_h)
  }
end

#evaluate_hypothesis(hypothesis_id:) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb', line 53

def evaluate_hypothesis(hypothesis_id:, **)
  h = hypothesis_engine.evaluate(hypothesis_id)
  unless h
    log.debug "[hypothesis_testing] evaluate failed: #{hypothesis_id[0..7]} not found"
    return { found: false }
  end

  log.debug "[hypothesis_testing] evaluated #{hypothesis_id[0..7]} status=#{h.status}"
  {
    found:            true,
    hypothesis_id:    h.id,
    status:           h.status,
    posterior:        h.posterior,
    confidence_label: h.confidence_label,
    evidence_count:   h.evidence_count
  }
end

#get_hypothesis(hypothesis_id:) ⇒ Object



97
98
99
100
101
102
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb', line 97

def get_hypothesis(hypothesis_id:, **)
  h = hypothesis_engine.hypotheses[hypothesis_id]
  return { found: false } unless h

  { found: true, hypothesis: h.to_h }
end

#hypothesis_reportObject



90
91
92
93
94
95
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb', line 90

def hypothesis_report(**)
  report = hypothesis_engine.hypothesis_report
  log.debug "[hypothesis_testing] report total=#{report[:total]} " \
            "confirmation_rate=#{report[:confirmation_rate].round(4)}"
  report
end

#most_confident_hypotheses(limit: 5) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb', line 81

def most_confident_hypotheses(limit: 5, **)
  hypotheses = hypothesis_engine.most_confident(limit: limit)
  log.debug "[hypothesis_testing] most_confident count=#{hypotheses.size}"
  {
    count:      hypotheses.size,
    hypotheses: hypotheses.map(&:to_h)
  }
end

#propose_hypothesis(description:, domain: 'general', prior: Helpers::Constants::PRIOR_DEFAULT) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb', line 15

def propose_hypothesis(description:, domain: 'general', prior: Helpers::Constants::PRIOR_DEFAULT, **)
  h = hypothesis_engine.propose(description: description, domain: domain, prior: prior)
  log.debug "[hypothesis_testing] proposed id=#{h.id[0..7]} domain=#{domain} prior=#{prior}"
  {
    hypothesis_id:    h.id,
    description:      h.description,
    domain:           h.domain,
    prior:            h.prior,
    posterior:        h.posterior,
    status:           h.status,
    confidence_label: h.confidence_label
  }
end

#test_hypothesis(hypothesis_id:, evidence_strength:, supporting: true) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/legion/extensions/agentic/inference/hypothesis_testing/runners/hypothesis_testing.rb', line 29

def test_hypothesis(hypothesis_id:, evidence_strength:, supporting: true, **)
  h = hypothesis_engine.test_hypothesis(
    hypothesis_id:     hypothesis_id,
    evidence_strength: evidence_strength,
    supporting:        supporting
  )
  unless h
    log.debug "[hypothesis_testing] test failed: #{hypothesis_id[0..7]} not found"
    return { tested: false, reason: :not_found }
  end

  log.info "[hypothesis_testing] tested #{hypothesis_id[0..7]} " \
           "supporting=#{supporting} strength=#{evidence_strength} " \
           "posterior=#{h.posterior.round(4)} status=#{h.status}"
  {
    tested:           true,
    hypothesis_id:    h.id,
    posterior:        h.posterior,
    evidence_count:   h.evidence_count,
    status:           h.status,
    confidence_label: h.confidence_label
  }
end