Class: Legion::Extensions::Agentic::Inference::ArgumentMapping::Helpers::Argument

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb

Constant Summary

Constants included from Constants

Constants::ARGUMENT_STRENGTHS, Constants::BACKING_WEIGHT, Constants::DECAY_RATE, Constants::DEFAULT_STRENGTH, Constants::GROUND_WEIGHT, Constants::MAX_ARGUMENTS, Constants::MAX_HISTORY, Constants::QUALIFIER_TYPES, Constants::REBUTTAL_IMPACT_LABELS, Constants::REBUTTAL_PENALTY, Constants::WARRANT_WEIGHT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, claim:, domain: :general, warrant: nil, qualifier: :presumably) ⇒ Argument

Returns a new instance of Argument.



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

def initialize(id:, claim:, domain: :general, warrant: nil, qualifier: :presumably)
  @id         = id
  @claim      = claim
  @domain     = domain
  @warrant    = warrant
  @qualifier  = qualifier
  @grounds    = []
  @backing    = []
  @rebuttals  = []
  @created_at = Time.now.utc
end

Instance Attribute Details

#backingObject (readonly)

Returns the value of attribute backing.



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

def backing
  @backing
end

#claimObject (readonly)

Returns the value of attribute claim.



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

def claim
  @claim
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#domainObject (readonly)

Returns the value of attribute domain.



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

def domain
  @domain
end

#groundsObject (readonly)

Returns the value of attribute grounds.



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

def grounds
  @grounds
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#qualifierObject (readonly)

Returns the value of attribute qualifier.



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

def qualifier
  @qualifier
end

#rebuttalsObject (readonly)

Returns the value of attribute rebuttals.



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

def rebuttals
  @rebuttals
end

#warrantObject (readonly)

Returns the value of attribute warrant.



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

def warrant
  @warrant
end

Instance Method Details

#add_backing(backing:) ⇒ Object



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

def add_backing(backing:)
  @backing << backing
end

#add_ground(ground:) ⇒ Object



27
28
29
# File 'lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb', line 27

def add_ground(ground:)
  @grounds << ground
end

#add_rebuttal(content:, impact: 0.5) ⇒ Object



35
36
37
# File 'lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb', line 35

def add_rebuttal(content:, impact: 0.5)
  @rebuttals << { content: content, impact: impact.clamp(0.0, 1.0) }
end

#rebutted?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb', line 55

def rebutted?
  @rebuttals.any? { |r| r[:impact] > 0.5 }
end

#sound?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb', line 51

def sound?
  strength >= 0.6 && !@warrant.nil? && !@grounds.empty?
end

#strengthObject



39
40
41
42
43
44
45
# File 'lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb', line 39

def strength
  raw = (ground_score * GROUND_WEIGHT) +
        (warrant_score * WARRANT_WEIGHT) +
        (backing_score * BACKING_WEIGHT) -
        (rebuttal_score * REBUTTAL_PENALTY)
  raw.clamp(0.0, 1.0)
end

#strength_labelObject



47
48
49
# File 'lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb', line 47

def strength_label
  ARGUMENT_STRENGTHS.find { |range, _| range.cover?(strength) }&.last
end

#to_hObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/legion/extensions/agentic/inference/argument_mapping/helpers/argument.rb', line 59

def to_h
  {
    id:             @id,
    claim:          @claim,
    domain:         @domain,
    grounds:        @grounds,
    warrant:        @warrant,
    backing:        @backing,
    qualifier:      @qualifier,
    rebuttals:      @rebuttals,
    strength:       strength,
    strength_label: strength_label,
    sound:          sound?,
    rebutted:       rebutted?,
    created_at:     @created_at
  }
end