Class: SuperInstance::Equipment::ConsensusEngine::ConsensusEngine
- Inherits:
-
Object
- Object
- SuperInstance::Equipment::ConsensusEngine::ConsensusEngine
- Defined in:
- lib/equipment/consensus_engine/consensus_engine.rb
Overview
ConsensusEngine - Main equipment class for multi-agent deliberation
Coordinates the tripartite deliberation process across Pathos (intent/emotion), Logos (logic/reason), and Ethos (truth/ethics) perspectives to build consensus.
Instance Method Summary collapse
-
#clear_audit_trail ⇒ Object
Clears the audit trail.
-
#deliberate(input) ⇒ Hash
Conducts a deliberation on a proposition to reach consensus.
-
#get_audit_trail ⇒ Array<Hash>
Gets the current audit trail.
-
#get_config ⇒ Hash
Gets the current configuration.
-
#initialize(config = {}) ⇒ ConsensusEngine
constructor
Creates a new ConsensusEngine instance.
-
#update_domain_weights(domain, weights) ⇒ Object
Updates the weight profile for a specific domain.
Constructor Details
#initialize(config = {}) ⇒ ConsensusEngine
Creates a new ConsensusEngine instance
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/equipment/consensus_engine/consensus_engine.rb', line 31 def initialize(config = {}) @config = { max_rounds: config[:max_rounds] || 5, confidence_threshold: config[:confidence_threshold] || 0.7, include_dissent: config.fetch(:include_dissent, true), domain: config[:domain] || :balanced, custom_weights: config[:custom_weights], enable_audit: config.fetch(:enable_audit, true), timeout: config[:timeout] || 30000 } @deliberation = TripartiteDeliberation.new @weight_calculator = WeightCalculator.new(@config[:custom_weights]) @conflict_resolution = ConflictResolution.new @audit_trail = [] @audit_id_counter = 0 add_audit_entry(:deliberation_start, 'ConsensusEngine initialized', { config: @config }) end |
Instance Method Details
#clear_audit_trail ⇒ Object
Clears the audit trail
154 155 156 157 |
# File 'lib/equipment/consensus_engine/consensus_engine.rb', line 154 def clear_audit_trail @audit_trail.clear @audit_id_counter = 0 end |
#deliberate(input) ⇒ Hash
Conducts a deliberation on a proposition to reach consensus
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/equipment/consensus_engine/consensus_engine.rb', line 54 def deliberate(input) start_time = Time.now.to_f * 1000 domain = input[:domain_override] || @config[:domain] add_audit_entry( :deliberation_start, "Starting deliberation on: #{input[:proposition]}", { domain: domain, context: input[:context] } ) rounds = [] resolved_conflicts = [] consensus_reached = false final_opinions = [] begin # Conduct deliberation rounds round_num = 1 while round_num <= @config[:max_rounds] && !consensus_reached round = conduct_round(round_num, input, domain, final_opinions) rounds << round # Check for conflicts conflicts = detect_conflicts(round[:opinions]) if conflicts.any? add_audit_entry( :conflict_detected, "Detected #{conflicts.length} conflicts in round #{round_num}", { conflicts: conflicts.map { |c| { type: c[:type], perspectives: c[:perspectives] } } } ) conflicts.each do |conflict| resolution = @conflict_resolution.resolve(conflict, round[:opinions]) resolved_conflicts << resolution add_audit_entry( :conflict_resolved, "Resolved conflict: #{conflict[:type]}", { strategy: resolution[:strategy], outcome: resolution[:outcome] } ) end end # Check for consensus consensus_reached = evaluate_consensus(round[:opinions]) if consensus_reached add_audit_entry( :consensus_reached, "Consensus reached in round #{round_num}", { consensus_score: round[:interim_score] } ) end final_opinions = round[:opinions] round_num += 1 end # Calculate final confidence and verdict verdict = synthesize_verdict(final_opinions, consensus_reached) confidence = calculate_overall_confidence(final_opinions, consensus_reached) dissenting_opinions = @config[:include_dissent] ? final_opinions.select { |op| op[:confidence] < @config[:confidence_threshold] } : nil duration_ms = (Time.now.to_f * 1000 - start_time).to_i add_audit_entry(:deliberation_complete, 'Deliberation completed', { consensus_reached: consensus_reached, verdict: verdict, confidence: confidence, duration_ms: duration_ms }) { consensus: consensus_reached, verdict: verdict, confidence: confidence, perspectives: final_opinions, rounds: rounds, resolved_conflicts: resolved_conflicts, dissenting_opinions: dissenting_opinions, audit_trail: @audit_trail.dup, metadata: { duration_ms: duration_ms, rounds_completed: rounds.length, forced_consensus: !consensus_reached && rounds.length >= @config[:max_rounds], domain: domain, weight_profile: @weight_calculator.get_profile(domain), conflicts_resolved: resolved_conflicts.length } } rescue StandardError => e = e. add_audit_entry(:error, "Deliberation failed: #{}", { error: }) raise end end |
#get_audit_trail ⇒ Array<Hash>
Gets the current audit trail
161 162 163 |
# File 'lib/equipment/consensus_engine/consensus_engine.rb', line 161 def get_audit_trail @audit_trail.dup end |
#get_config ⇒ Hash
Gets the current configuration
174 175 176 |
# File 'lib/equipment/consensus_engine/consensus_engine.rb', line 174 def get_config @config.dup end |
#update_domain_weights(domain, weights) ⇒ Object
Updates the weight profile for a specific domain
168 169 170 |
# File 'lib/equipment/consensus_engine/consensus_engine.rb', line 168 def update_domain_weights(domain, weights) @weight_calculator.set_profile(domain, weights) end |