Class: Legion::Extensions::Agentic::Social::Conscience::Helpers::MoralStore
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Social::Conscience::Helpers::MoralStore
- Defined in:
- lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb
Instance Attribute Summary collapse
-
#dilemmas ⇒ Object
readonly
Returns the value of attribute dilemmas.
-
#evaluator ⇒ Object
readonly
Returns the value of attribute evaluator.
-
#history ⇒ Object
readonly
Returns the value of attribute history.
-
#sensitivity_snapshots ⇒ Object
readonly
Returns the value of attribute sensitivity_snapshots.
Instance Method Summary collapse
-
#aggregate_stats ⇒ Object
Aggregate stats across all evaluations.
-
#consistency_score ⇒ Object
Ratio of evaluations where the agent followed its moral verdict.
-
#foundation_sensitivities ⇒ Object
Current foundation sensitivities from the evaluator.
-
#initialize(evaluator: nil) ⇒ MoralStore
constructor
A new instance of MoralStore.
-
#open_dilemmas ⇒ Object
Open dilemmas (not yet resolved).
-
#recent_evaluations(limit = 20) ⇒ Object
Recent evaluations, newest last.
-
#record_evaluation(result) ⇒ Object
Store a completed moral evaluation result.
-
#record_follow_through(verdict, outcome) ⇒ Object
Record whether the agent followed its moral verdict or overrode it.
Constructor Details
#initialize(evaluator: nil) ⇒ MoralStore
Returns a new instance of MoralStore.
12 13 14 15 16 17 18 19 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 12 def initialize(evaluator: nil) @evaluator = evaluator || MoralEvaluator.new @history = [] @dilemmas = [] @sensitivity_snapshots = [] @followed_count = 0 @overridden_count = 0 end |
Instance Attribute Details
#dilemmas ⇒ Object (readonly)
Returns the value of attribute dilemmas.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 10 def dilemmas @dilemmas end |
#evaluator ⇒ Object (readonly)
Returns the value of attribute evaluator.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 10 def evaluator @evaluator end |
#history ⇒ Object (readonly)
Returns the value of attribute history.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 10 def history @history end |
#sensitivity_snapshots ⇒ Object (readonly)
Returns the value of attribute sensitivity_snapshots.
10 11 12 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 10 def sensitivity_snapshots @sensitivity_snapshots end |
Instance Method Details
#aggregate_stats ⇒ Object
Aggregate stats across all evaluations
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 70 def aggregate_stats verdict_counts = Hash.new(0) @history.each { |e| verdict_counts[e[:verdict]] += 1 } { total_evaluations: @history.size, verdict_counts: verdict_counts, dilemma_count: @dilemmas.size, consistency_score: consistency_score, followed_count: @followed_count, overridden_count: @overridden_count, foundation_sensitivities: foundation_sensitivities } end |
#consistency_score ⇒ Object
Ratio of evaluations where the agent followed its moral verdict
47 48 49 50 51 52 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 47 def consistency_score total = @followed_count + @overridden_count return 1.0 if total.zero? (@followed_count.to_f / total).round(4) end |
#foundation_sensitivities ⇒ Object
Current foundation sensitivities from the evaluator
55 56 57 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 55 def foundation_sensitivities @evaluator.sensitivities.transform_values { |s| s.round(4) } end |
#open_dilemmas ⇒ Object
Open dilemmas (not yet resolved)
65 66 67 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 65 def open_dilemmas @dilemmas.last(20) end |
#recent_evaluations(limit = 20) ⇒ Object
Recent evaluations, newest last
60 61 62 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 60 def recent_evaluations(limit = 20) @history.last(limit) end |
#record_evaluation(result) ⇒ Object
Store a completed moral evaluation result
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 22 def record_evaluation(result) @history << result @history.shift while @history.size > Constants::MAX_MORAL_HISTORY @dilemmas << result[:dilemma] if result[:dilemma] snapshot_sensitivities(result[:verdict]) result end |
#record_follow_through(verdict, outcome) ⇒ Object
Record whether the agent followed its moral verdict or overrode it. outcome: :followed | :overridden
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/agentic/social/conscience/helpers/moral_store.rb', line 35 def record_follow_through(verdict, outcome) if outcome == :followed @followed_count += 1 else @overridden_count += 1 end # Feed back into evaluator sensitivities foundation_feedback(verdict, outcome) end |