Module: Legion::Extensions::Agentic::Social::PerspectiveShifting::Runners::PerspectiveShifting
- Includes:
- Helpers::Lex
- Included in:
- Client
- Defined in:
- lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb
Instance Method Summary collapse
-
#add_perspective(name:, type: :stakeholder, priorities: [], empathy: Helpers::Constants::DEFAULT_EMPATHY, bias: nil, expertise_domains: [], engine: nil) ⇒ Object
— Perspective management —.
-
#add_situation(content:, engine: nil) ⇒ Object
— Situation management —.
- #blind_spots(situation_id:, engine: nil) ⇒ Object
- #coverage_score(situation_id:, engine: nil) ⇒ Object
- #dominant_view(situation_id:, engine: nil) ⇒ Object
- #engine_status(engine: nil) ⇒ Object
-
#generate_view(situation_id:, perspective_id:, valence: 0.0, concerns: [], opportunities: [], confidence: 0.5, engine: nil) ⇒ Object
— View generation and retrieval —.
- #get_perspective(perspective_id:, engine: nil) ⇒ Object
- #list_perspectives(engine: nil) ⇒ Object
- #list_situations(engine: nil) ⇒ Object
- #most_divergent_pair(situation_id:, engine: nil) ⇒ Object
-
#perspective_agreement(situation_id:, engine: nil) ⇒ Object
— Analysis —.
- #synthesize(situation_id:, engine: nil) ⇒ Object
- #views_for_situation(situation_id:, engine: nil) ⇒ Object
Instance Method Details
#add_perspective(name:, type: :stakeholder, priorities: [], empathy: Helpers::Constants::DEFAULT_EMPATHY, bias: nil, expertise_domains: [], engine: nil) ⇒ Object
— Perspective management —
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 17 def add_perspective(name:, type: :stakeholder, priorities: [], empathy: Helpers::Constants::DEFAULT_EMPATHY, bias: nil, expertise_domains: [], engine: nil, **) eng = engine || shifting_engine result = eng.add_perspective(name: name, type: type, priorities: priorities, empathy: empathy, bias: bias, expertise_domains: expertise_domains) return { success: false, error: result[:error] } if result.is_a?(Hash) && result[:error] log.debug "[perspective_shifting] added perspective name=#{name} type=#{type} id=#{result.id[0..7]}" { success: true, perspective: result.to_h } end |
#add_situation(content:, engine: nil) ⇒ Object
— Situation management —
48 49 50 51 52 53 54 55 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 48 def add_situation(content:, engine: nil, **) eng = engine || shifting_engine result = eng.add_situation(content: content) return { success: false, error: result[:error] } if result.is_a?(Hash) && result[:error] log.debug "[perspective_shifting] added situation id=#{result[:id][0..7]}" { success: true, situation_id: result[:id], content: result[:content] } end |
#blind_spots(situation_id:, engine: nil) ⇒ Object
101 102 103 104 105 106 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 101 def blind_spots(situation_id:, engine: nil, **) eng = engine || shifting_engine spots = eng.blind_spots(situation_id: situation_id) log.debug "[perspective_shifting] blind_spots situation=#{situation_id[0..7]} count=#{spots.size}" { success: true, situation_id: situation_id, blind_spots: spots, count: spots.size } end |
#coverage_score(situation_id:, engine: nil) ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 108 def coverage_score(situation_id:, engine: nil, **) eng = engine || shifting_engine score = eng.coverage_score(situation_id: situation_id) label = Helpers::Constants.coverage_label(score) log.debug "[perspective_shifting] coverage situation=#{situation_id[0..7]} score=#{score.round(2)} label=#{label}" { success: true, situation_id: situation_id, coverage: score, label: label } end |
#dominant_view(situation_id:, engine: nil) ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 116 def dominant_view(situation_id:, engine: nil, **) eng = engine || shifting_engine view = eng.dominant_view(situation_id: situation_id) if view log.debug "[perspective_shifting] dominant_view situation=#{situation_id[0..7]} confidence=#{view.confidence.round(2)}" { success: true, found: true, view: view.to_h } else { success: true, found: false } end end |
#engine_status(engine: nil) ⇒ Object
150 151 152 153 154 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 150 def engine_status(engine: nil, **) eng = engine || shifting_engine log.debug '[perspective_shifting] engine_status' { success: true }.merge(eng.to_h) end |
#generate_view(situation_id:, perspective_id:, valence: 0.0, concerns: [], opportunities: [], confidence: 0.5, engine: nil) ⇒ Object
— View generation and retrieval —
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 66 def generate_view(situation_id:, perspective_id:, valence: 0.0, concerns: [], opportunities: [], confidence: 0.5, engine: nil, **) eng = engine || shifting_engine result = eng.generate_view( situation_id: situation_id, perspective_id: perspective_id, valence: valence, concerns: concerns, opportunities: opportunities, confidence: confidence ) return { success: false, error: result[:error] } if result.is_a?(Hash) && result[:error] log.debug "[perspective_shifting] generated view id=#{result.id[0..7]} " \ "valence=#{result.valence.round(2)}" { success: true, view: result.to_h } end |
#get_perspective(perspective_id:, engine: nil) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 35 def get_perspective(perspective_id:, engine: nil, **) eng = engine || shifting_engine persp = eng.perspectives[perspective_id] if persp { success: true, found: true, perspective: persp.to_h } else log.debug "[perspective_shifting] perspective not found id=#{perspective_id[0..7]}" { success: false, found: false } end end |
#list_perspectives(engine: nil) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 28 def list_perspectives(engine: nil, **) eng = engine || shifting_engine persp = eng.perspectives.values.map(&:to_h) log.debug "[perspective_shifting] list_perspectives count=#{persp.size}" { success: true, perspectives: persp, count: persp.size } end |
#list_situations(engine: nil) ⇒ Object
57 58 59 60 61 62 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 57 def list_situations(engine: nil, **) eng = engine || shifting_engine sits = eng.situations.values.map { |s| s.merge(views: s[:views].map(&:to_h)) } log.debug "[perspective_shifting] list_situations count=#{sits.size}" { success: true, situations: sits, count: sits.size } end |
#most_divergent_pair(situation_id:, engine: nil) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 137 def most_divergent_pair(situation_id:, engine: nil, **) eng = engine || shifting_engine pair = eng.most_divergent_pair(situation_id: situation_id) unless pair log.debug '[perspective_shifting] most_divergent_pair: not enough views' return { success: true, found: false } end divergence = (pair[0].valence - pair[1].valence).abs.round(10) log.debug "[perspective_shifting] most_divergent_pair divergence=#{divergence.round(2)}" { success: true, found: true, views: pair.map(&:to_h), divergence: divergence } end |
#perspective_agreement(situation_id:, engine: nil) ⇒ Object
— Analysis —
93 94 95 96 97 98 99 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 93 def perspective_agreement(situation_id:, engine: nil, **) eng = engine || shifting_engine score = eng.perspective_agreement(situation_id: situation_id) label = Helpers::Constants.agreement_label(score) log.debug "[perspective_shifting] agreement situation=#{situation_id[0..7]} score=#{score.round(2)} label=#{label}" { success: true, situation_id: situation_id, agreement: score, label: label } end |
#synthesize(situation_id:, engine: nil) ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 127 def synthesize(situation_id:, engine: nil, **) eng = engine || shifting_engine result = eng.synthesize(situation_id: situation_id) return { success: false, error: result[:error] } if result[:error] log.info "[perspective_shifting] synthesized situation=#{situation_id[0..7]} " \ "valence=#{result[:weighted_valence].round(2)} views=#{result[:view_count]}" result.merge(success: true) end |
#views_for_situation(situation_id:, engine: nil) ⇒ Object
84 85 86 87 88 89 |
# File 'lib/legion/extensions/agentic/social/perspective_shifting/runners/perspective_shifting.rb', line 84 def views_for_situation(situation_id:, engine: nil, **) eng = engine || shifting_engine views = eng.views_for_situation(situation_id: situation_id) log.debug "[perspective_shifting] views_for_situation id=#{situation_id[0..7]} count=#{views.size}" { success: true, views: views.map(&:to_h), count: views.size } end |