Class: Legion::Extensions::Agentic::Inference::Horizon::Helpers::HorizonEngine
- Inherits:
-
Object
- Object
- Legion::Extensions::Agentic::Inference::Horizon::Helpers::HorizonEngine
- Defined in:
- lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb
Instance Attribute Summary collapse
-
#current_horizon ⇒ Object
readonly
Returns the value of attribute current_horizon.
-
#projections ⇒ Object
readonly
Returns the value of attribute projections.
-
#stress_level ⇒ Object
readonly
Returns the value of attribute stress_level.
Instance Method Summary collapse
- #add_projection(description:, domain: :general, horizon_distance: nil, confidence: 1.0) ⇒ Object
- #apply_stress!(level) ⇒ Object
- #beyond_horizon_projections ⇒ Object
- #construal_label ⇒ Object
- #contract_horizon!(amount: Constants::HORIZON_CONTRACT) ⇒ Object
- #effective_horizon ⇒ Object
- #expand_horizon!(amount: Constants::HORIZON_EXPAND) ⇒ Object
- #farthest_projections(num: 5) ⇒ Object
- #horizon_report ⇒ Object
-
#initialize(initial_horizon: Constants::DEFAULT_HORIZON) ⇒ HorizonEngine
constructor
A new instance of HorizonEngine.
- #nearest_projections(num: 5) ⇒ Object
- #projections_within_horizon ⇒ Object
- #relieve_stress!(amount: 0.1) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(initial_horizon: Constants::DEFAULT_HORIZON) ⇒ HorizonEngine
Returns a new instance of HorizonEngine.
12 13 14 15 16 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 12 def initialize(initial_horizon: Constants::DEFAULT_HORIZON) @projections = [] @current_horizon = initial_horizon.clamp(Constants::MIN_HORIZON, Constants::MAX_HORIZON) @stress_level = 0.0 end |
Instance Attribute Details
#current_horizon ⇒ Object (readonly)
Returns the value of attribute current_horizon.
10 11 12 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 10 def current_horizon @current_horizon end |
#projections ⇒ Object (readonly)
Returns the value of attribute projections.
10 11 12 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 10 def projections @projections end |
#stress_level ⇒ Object (readonly)
Returns the value of attribute stress_level.
10 11 12 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 10 def stress_level @stress_level end |
Instance Method Details
#add_projection(description:, domain: :general, horizon_distance: nil, confidence: 1.0) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 18 def add_projection(description:, domain: :general, horizon_distance: nil, confidence: 1.0) dist = horizon_distance || @current_horizon proj = Projection.new( description: description, domain: domain, horizon_distance: dist, confidence: confidence ) @projections << proj @projections = @projections.last(Constants::MAX_PROJECTIONS) if @projections.size > Constants::MAX_PROJECTIONS proj end |
#apply_stress!(level) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 41 def apply_stress!(level) @stress_level = level.clamp(0.0, 1.0) @current_horizon = (@current_horizon - (@stress_level * Constants::STRESS_CONTRACTION)) .clamp(Constants::MIN_HORIZON, Constants::MAX_HORIZON) @current_horizon end |
#beyond_horizon_projections ⇒ Object
62 63 64 65 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 62 def beyond_horizon_projections eh = effective_horizon @projections.select { |p| p.horizon_distance > eh } end |
#construal_label ⇒ Object
75 76 77 78 79 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 75 def construal_label dist = effective_horizon entry = Constants::CONSTRUAL_LABELS.find { |e| e[:range].cover?(dist) } entry ? entry[:label] : :balanced end |
#contract_horizon!(amount: Constants::HORIZON_CONTRACT) ⇒ Object
36 37 38 39 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 36 def contract_horizon!(amount: Constants::HORIZON_CONTRACT) @current_horizon = (@current_horizon - amount).clamp(Constants::MIN_HORIZON, Constants::MAX_HORIZON) @current_horizon end |
#effective_horizon ⇒ Object
52 53 54 55 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 52 def effective_horizon (@current_horizon - (@stress_level * Constants::STRESS_CONTRACTION)) .clamp(Constants::MIN_HORIZON, Constants::MAX_HORIZON) end |
#expand_horizon!(amount: Constants::HORIZON_EXPAND) ⇒ Object
31 32 33 34 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 31 def (amount: Constants::HORIZON_EXPAND) @current_horizon = (@current_horizon + amount).clamp(Constants::MIN_HORIZON, Constants::MAX_HORIZON) @current_horizon end |
#farthest_projections(num: 5) ⇒ Object
71 72 73 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 71 def farthest_projections(num: 5) @projections.sort_by(&:horizon_distance).last(num).reverse end |
#horizon_report ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 81 def horizon_report { current_horizon: @current_horizon.round(10), stress_level: @stress_level.round(10), effective_horizon: effective_horizon.round(10), construal_label: construal_label, horizon_level: horizon_level, total_projections: @projections.size, within_horizon: projections_within_horizon.size, beyond_horizon: beyond_horizon_projections.size } end |
#nearest_projections(num: 5) ⇒ Object
67 68 69 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 67 def nearest_projections(num: 5) @projections.sort_by(&:horizon_distance).first(num) end |
#projections_within_horizon ⇒ Object
57 58 59 60 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 57 def projections_within_horizon eh = effective_horizon @projections.select { |p| p.horizon_distance <= eh } end |
#relieve_stress!(amount: 0.1) ⇒ Object
48 49 50 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 48 def relieve_stress!(amount: 0.1) @stress_level = (@stress_level - amount).clamp(0.0, 1.0) end |
#to_h ⇒ Object
94 95 96 |
# File 'lib/legion/extensions/agentic/inference/horizon/helpers/horizon_engine.rb', line 94 def to_h horizon_report.merge(projections: @projections.map(&:to_h)) end |