lex-agentic-integration 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +5 -0
- data/LICENSE +21 -0
- data/README.md +13 -0
- data/lex-agentic-integration.gemspec +30 -0
- data/lib/legion/extensions/agentic/integration/boundary/client.rb +15 -0
- data/lib/legion/extensions/agentic/integration/boundary/helpers/boundary.rb +90 -0
- data/lib/legion/extensions/agentic/integration/boundary/helpers/boundary_engine.rb +123 -0
- data/lib/legion/extensions/agentic/integration/boundary/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/integration/boundary/runners/cognitive_boundary.rb +100 -0
- data/lib/legion/extensions/agentic/integration/boundary/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/boundary.rb +19 -0
- data/lib/legion/extensions/agentic/integration/context/client.rb +26 -0
- data/lib/legion/extensions/agentic/integration/context/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/integration/context/helpers/context_manager.rb +150 -0
- data/lib/legion/extensions/agentic/integration/context/helpers/frame.rb +99 -0
- data/lib/legion/extensions/agentic/integration/context/runners/context.rb +94 -0
- data/lib/legion/extensions/agentic/integration/context/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/context.rb +19 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/helpers/constants.rb +51 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/helpers/distribution_engine.rb +159 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/helpers/participant.rb +100 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/runners/distributed_cognition.rb +107 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/distributed_cognition.rb +19 -0
- data/lib/legion/extensions/agentic/integration/gestalt/client.rb +21 -0
- data/lib/legion/extensions/agentic/integration/gestalt/helpers/constants.rb +51 -0
- data/lib/legion/extensions/agentic/integration/gestalt/helpers/pattern.rb +90 -0
- data/lib/legion/extensions/agentic/integration/gestalt/helpers/pattern_store.rb +123 -0
- data/lib/legion/extensions/agentic/integration/gestalt/runners/gestalt.rb +82 -0
- data/lib/legion/extensions/agentic/integration/gestalt/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/gestalt.rb +19 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/actors/competition.rb +45 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/client.rb +29 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/helpers/broadcast.rb +62 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/helpers/competitor.rb +59 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/helpers/constants.rb +65 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/helpers/workspace.rb +188 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb +104 -0
- data/lib/legion/extensions/agentic/integration/global_workspace/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/global_workspace.rb +20 -0
- data/lib/legion/extensions/agentic/integration/integration/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/integration/helpers/constants.rb +62 -0
- data/lib/legion/extensions/agentic/integration/integration/helpers/integrated_representation.rb +106 -0
- data/lib/legion/extensions/agentic/integration/integration/helpers/integration_engine.rb +163 -0
- data/lib/legion/extensions/agentic/integration/integration/helpers/modal_signal.rb +62 -0
- data/lib/legion/extensions/agentic/integration/integration/runners/cognitive_integration.rb +105 -0
- data/lib/legion/extensions/agentic/integration/integration/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/integration.rb +20 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/actors/thread_walker.rb +45 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/client.rb +23 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/helpers/constants.rb +39 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/helpers/labyrinth.rb +138 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/helpers/labyrinth_engine.rb +177 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/helpers/node.rb +64 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/runners/cognitive_labyrinth.rb +128 -0
- data/lib/legion/extensions/agentic/integration/labyrinth/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/labyrinth.rb +22 -0
- data/lib/legion/extensions/agentic/integration/map/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/integration/map/client.rb +29 -0
- data/lib/legion/extensions/agentic/integration/map/helpers/cognitive_map_store.rb +179 -0
- data/lib/legion/extensions/agentic/integration/map/helpers/constants.rb +71 -0
- data/lib/legion/extensions/agentic/integration/map/helpers/graph_traversal.rb +124 -0
- data/lib/legion/extensions/agentic/integration/map/helpers/location.rb +71 -0
- data/lib/legion/extensions/agentic/integration/map/runners/cognitive_map.rb +95 -0
- data/lib/legion/extensions/agentic/integration/map/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/map.rb +20 -0
- data/lib/legion/extensions/agentic/integration/mosaic/client.rb +15 -0
- data/lib/legion/extensions/agentic/integration/mosaic/helpers/constants.rb +55 -0
- data/lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic.rb +111 -0
- data/lib/legion/extensions/agentic/integration/mosaic/helpers/mosaic_engine.rb +124 -0
- data/lib/legion/extensions/agentic/integration/mosaic/helpers/tessera.rb +86 -0
- data/lib/legion/extensions/agentic/integration/mosaic/runners/cognitive_mosaic.rb +76 -0
- data/lib/legion/extensions/agentic/integration/mosaic/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/mosaic.rb +22 -0
- data/lib/legion/extensions/agentic/integration/mycelium/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/constants.rb +52 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/fruiting_body.rb +50 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/hypha.rb +76 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node.rb +72 -0
- data/lib/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine.rb +151 -0
- data/lib/legion/extensions/agentic/integration/mycelium/runners/cognitive_mycelium.rb +73 -0
- data/lib/legion/extensions/agentic/integration/mycelium/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/mycelium.rb +23 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/client.rb +25 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine.rb +156 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit.rb +72 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/constants.rb +35 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/helpers/stream.rb +51 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/runners/phenomenal_binding.rb +110 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/phenomenal_binding.rb +20 -0
- data/lib/legion/extensions/agentic/integration/qualia/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/qualia/helpers/constants.rb +74 -0
- data/lib/legion/extensions/agentic/integration/qualia/helpers/quale.rb +103 -0
- data/lib/legion/extensions/agentic/integration/qualia/helpers/qualia_engine.rb +142 -0
- data/lib/legion/extensions/agentic/integration/qualia/runners/qualia.rb +67 -0
- data/lib/legion/extensions/agentic/integration/qualia/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/qualia.rb +19 -0
- data/lib/legion/extensions/agentic/integration/situation_model/client.rb +28 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/client.rb +23 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/constants.rb +40 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/situation_engine.rb +73 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/situation_event.rb +56 -0
- data/lib/legion/extensions/agentic/integration/situation_model/helpers/situation_model.rb +90 -0
- data/lib/legion/extensions/agentic/integration/situation_model/runners/situation_model.rb +99 -0
- data/lib/legion/extensions/agentic/integration/situation_model/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/situation_model.rb +21 -0
- data/lib/legion/extensions/agentic/integration/synthesis/client.rb +29 -0
- data/lib/legion/extensions/agentic/integration/synthesis/helpers/constants.rb +41 -0
- data/lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis.rb +63 -0
- data/lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_engine.rb +213 -0
- data/lib/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream.rb +67 -0
- data/lib/legion/extensions/agentic/integration/synthesis/runners/cognitive_synthesis.rb +82 -0
- data/lib/legion/extensions/agentic/integration/synthesis/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/synthesis.rb +20 -0
- data/lib/legion/extensions/agentic/integration/tapestry/client.rb +15 -0
- data/lib/legion/extensions/agentic/integration/tapestry/helpers/constants.rb +46 -0
- data/lib/legion/extensions/agentic/integration/tapestry/helpers/loom_engine.rb +125 -0
- data/lib/legion/extensions/agentic/integration/tapestry/helpers/tapestry.rb +144 -0
- data/lib/legion/extensions/agentic/integration/tapestry/helpers/thread.rb +112 -0
- data/lib/legion/extensions/agentic/integration/tapestry/runners/cognitive_tapestry.rb +81 -0
- data/lib/legion/extensions/agentic/integration/tapestry/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/tapestry.rb +22 -0
- data/lib/legion/extensions/agentic/integration/tessellation/client.rb +19 -0
- data/lib/legion/extensions/agentic/integration/tessellation/helpers/constants.rb +72 -0
- data/lib/legion/extensions/agentic/integration/tessellation/helpers/mosaic.rb +99 -0
- data/lib/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine.rb +141 -0
- data/lib/legion/extensions/agentic/integration/tessellation/helpers/tile.rb +76 -0
- data/lib/legion/extensions/agentic/integration/tessellation/runners/cognitive_tessellation.rb +58 -0
- data/lib/legion/extensions/agentic/integration/tessellation/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/tessellation.rb +22 -0
- data/lib/legion/extensions/agentic/integration/version.rb +11 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/client.rb +17 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/cognitive_signal.rb +38 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/constants.rb +64 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/trend_window.rb +80 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/helpers/zeitgeist_engine.rb +157 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/runners/cognitive_zeitgeist.rb +99 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist/version.rb +13 -0
- data/lib/legion/extensions/agentic/integration/zeitgeist.rb +22 -0
- data/lib/legion/extensions/agentic/integration.rb +34 -0
- data/spec/legion/extensions/agentic/integration/boundary/helpers/boundary_engine_spec.rb +165 -0
- data/spec/legion/extensions/agentic/integration/boundary/helpers/boundary_spec.rb +168 -0
- data/spec/legion/extensions/agentic/integration/boundary/helpers/constants_spec.rb +65 -0
- data/spec/legion/extensions/agentic/integration/boundary/runners/cognitive_boundary_spec.rb +111 -0
- data/spec/legion/extensions/agentic/integration/context/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/integration/context/helpers/constants_spec.rb +32 -0
- data/spec/legion/extensions/agentic/integration/context/helpers/context_manager_spec.rb +190 -0
- data/spec/legion/extensions/agentic/integration/context/helpers/frame_spec.rb +164 -0
- data/spec/legion/extensions/agentic/integration/context/runners/context_spec.rb +142 -0
- data/spec/legion/extensions/agentic/integration/distributed_cognition/client_spec.rb +21 -0
- data/spec/legion/extensions/agentic/integration/distributed_cognition/helpers/distribution_engine_spec.rb +149 -0
- data/spec/legion/extensions/agentic/integration/distributed_cognition/helpers/participant_spec.rb +116 -0
- data/spec/legion/extensions/agentic/integration/distributed_cognition/runners/distributed_cognition_spec.rb +102 -0
- data/spec/legion/extensions/agentic/integration/gestalt/client_spec.rb +53 -0
- data/spec/legion/extensions/agentic/integration/gestalt/helpers/constants_spec.rb +27 -0
- data/spec/legion/extensions/agentic/integration/gestalt/helpers/pattern_spec.rb +128 -0
- data/spec/legion/extensions/agentic/integration/gestalt/helpers/pattern_store_spec.rb +155 -0
- data/spec/legion/extensions/agentic/integration/gestalt/runners/gestalt_spec.rb +114 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/client_spec.rb +49 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/helpers/broadcast_spec.rb +83 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/helpers/competitor_spec.rb +84 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/helpers/workspace_spec.rb +174 -0
- data/spec/legion/extensions/agentic/integration/global_workspace/runners/global_workspace_spec.rb +118 -0
- data/spec/legion/extensions/agentic/integration/integration/cognitive_integration_spec.rb +7 -0
- data/spec/legion/extensions/agentic/integration/integration/helpers/integrated_representation_spec.rb +149 -0
- data/spec/legion/extensions/agentic/integration/integration/helpers/integration_engine_spec.rb +191 -0
- data/spec/legion/extensions/agentic/integration/integration/helpers/modal_signal_spec.rb +81 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/client_spec.rb +122 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/cognitive_labyrinth_spec.rb +19 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/helpers/constants_spec.rb +72 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/helpers/labyrinth_engine_spec.rb +222 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/helpers/labyrinth_spec.rb +235 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/helpers/node_spec.rb +157 -0
- data/spec/legion/extensions/agentic/integration/labyrinth/runners/cognitive_labyrinth_spec.rb +209 -0
- data/spec/legion/extensions/agentic/integration/map/client_spec.rb +89 -0
- data/spec/legion/extensions/agentic/integration/map/helpers/cognitive_map_store_spec.rb +321 -0
- data/spec/legion/extensions/agentic/integration/map/helpers/location_spec.rb +165 -0
- data/spec/legion/extensions/agentic/integration/map/runners/cognitive_map_spec.rb +190 -0
- data/spec/legion/extensions/agentic/integration/mosaic/client_spec.rb +16 -0
- data/spec/legion/extensions/agentic/integration/mosaic/helpers/constants_spec.rb +37 -0
- data/spec/legion/extensions/agentic/integration/mosaic/helpers/mosaic_engine_spec.rb +108 -0
- data/spec/legion/extensions/agentic/integration/mosaic/helpers/mosaic_spec.rb +120 -0
- data/spec/legion/extensions/agentic/integration/mosaic/helpers/tessera_spec.rb +92 -0
- data/spec/legion/extensions/agentic/integration/mosaic/runners/cognitive_mosaic_spec.rb +88 -0
- data/spec/legion/extensions/agentic/integration/mycelium/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/integration/mycelium/cognitive_mycelium_spec.rb +7 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/constants_spec.rb +28 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/fruiting_body_spec.rb +33 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/hypha_spec.rb +69 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/mycelial_node_spec.rb +79 -0
- data/spec/legion/extensions/agentic/integration/mycelium/helpers/mycelium_engine_spec.rb +136 -0
- data/spec/legion/extensions/agentic/integration/mycelium/runners/cognitive_mycelium_spec.rb +61 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/client_spec.rb +52 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_engine_spec.rb +290 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/helpers/binding_unit_spec.rb +195 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/helpers/constants_spec.rb +92 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/helpers/stream_spec.rb +128 -0
- data/spec/legion/extensions/agentic/integration/phenomenal_binding/runners/phenomenal_binding_spec.rb +174 -0
- data/spec/legion/extensions/agentic/integration/qualia/client_spec.rb +21 -0
- data/spec/legion/extensions/agentic/integration/qualia/helpers/quale_spec.rb +168 -0
- data/spec/legion/extensions/agentic/integration/qualia/helpers/qualia_engine_spec.rb +174 -0
- data/spec/legion/extensions/agentic/integration/qualia/qualia_spec.rb +7 -0
- data/spec/legion/extensions/agentic/integration/qualia/runners_spec.rb +70 -0
- data/spec/legion/extensions/agentic/integration/situation_model/client_spec.rb +51 -0
- data/spec/legion/extensions/agentic/integration/situation_model/helpers/constants_spec.rb +56 -0
- data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_engine_spec.rb +203 -0
- data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_event_spec.rb +94 -0
- data/spec/legion/extensions/agentic/integration/situation_model/helpers/situation_model_spec.rb +235 -0
- data/spec/legion/extensions/agentic/integration/situation_model/runners/situation_model_spec.rb +204 -0
- data/spec/legion/extensions/agentic/integration/synthesis/client_spec.rb +26 -0
- data/spec/legion/extensions/agentic/integration/synthesis/helpers/constants_spec.rb +87 -0
- data/spec/legion/extensions/agentic/integration/synthesis/helpers/synthesis_engine_spec.rb +233 -0
- data/spec/legion/extensions/agentic/integration/synthesis/helpers/synthesis_spec.rb +101 -0
- data/spec/legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream_spec.rb +116 -0
- data/spec/legion/extensions/agentic/integration/synthesis/runners/cognitive_synthesis_spec.rb +181 -0
- data/spec/legion/extensions/agentic/integration/tapestry/client_spec.rb +55 -0
- data/spec/legion/extensions/agentic/integration/tapestry/helpers/constants_spec.rb +88 -0
- data/spec/legion/extensions/agentic/integration/tapestry/helpers/loom_engine_spec.rb +225 -0
- data/spec/legion/extensions/agentic/integration/tapestry/helpers/tapestry_spec.rb +229 -0
- data/spec/legion/extensions/agentic/integration/tapestry/helpers/thread_spec.rb +211 -0
- data/spec/legion/extensions/agentic/integration/tapestry/runners/cognitive_tapestry_spec.rb +171 -0
- data/spec/legion/extensions/agentic/integration/tessellation/client_spec.rb +40 -0
- data/spec/legion/extensions/agentic/integration/tessellation/helpers/mosaic_spec.rb +99 -0
- data/spec/legion/extensions/agentic/integration/tessellation/helpers/tessellation_engine_spec.rb +145 -0
- data/spec/legion/extensions/agentic/integration/tessellation/helpers/tile_spec.rb +138 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/helpers/cognitive_signal_spec.rb +62 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/helpers/constants_spec.rb +73 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/helpers/trend_window_spec.rb +100 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/helpers/zeitgeist_engine_spec.rb +163 -0
- data/spec/legion/extensions/agentic/integration/zeitgeist/runners/cognitive_zeitgeist_spec.rb +165 -0
- data/spec/spec_helper.rb +46 -0
- metadata +320 -0
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module SituationModel
|
|
8
|
+
module Helpers
|
|
9
|
+
class SituationEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@models = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def create_model(label:)
|
|
17
|
+
model = SituationModel.new(label: label)
|
|
18
|
+
@models[model.id] = model
|
|
19
|
+
model
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def add_event_to_model(model_id:, content:, dimension_values: {})
|
|
23
|
+
model = @models[model_id]
|
|
24
|
+
return nil unless model
|
|
25
|
+
|
|
26
|
+
event = SituationEvent.new(content: content, dimension_values: dimension_values)
|
|
27
|
+
model.add_event(event)
|
|
28
|
+
event
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def model_coherence(model_id:)
|
|
32
|
+
@models[model_id]&.coherence
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def find_boundaries(model_id:, threshold: 0.3)
|
|
36
|
+
@models[model_id]&.event_boundaries(threshold: threshold)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def dimension_trajectory(model_id:, dimension:)
|
|
40
|
+
@models[model_id]&.dimension_trajectory(dimension)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def most_coherent(limit: 5)
|
|
44
|
+
@models.values
|
|
45
|
+
.sort_by { |m| -m.coherence }
|
|
46
|
+
.first(limit)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def models_by_label(label:)
|
|
50
|
+
@models.values.select { |m| m.label == label }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def decay_all
|
|
54
|
+
@models.each_value(&:decay!)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def prune_collapsed
|
|
58
|
+
@models.delete_if { |_, m| m.coherence <= 0.1 }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_h
|
|
62
|
+
{
|
|
63
|
+
model_count: @models.size,
|
|
64
|
+
models: @models.values.map(&:to_h)
|
|
65
|
+
}
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module SituationModel
|
|
8
|
+
module Helpers
|
|
9
|
+
class SituationEvent
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :content, :dimension_values, :created_at
|
|
13
|
+
|
|
14
|
+
def initialize(content:, dimension_values: {})
|
|
15
|
+
@content = content
|
|
16
|
+
@dimension_values = build_dimension_values(dimension_values)
|
|
17
|
+
@created_at = Time.now.utc
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def continuity_with(other_event)
|
|
21
|
+
total_diff = DIMENSIONS.sum do |dim|
|
|
22
|
+
(dimension_values[dim] - other_event.dimension_values[dim]).abs
|
|
23
|
+
end
|
|
24
|
+
avg_diff = total_diff / DIMENSIONS.size.to_f
|
|
25
|
+
1.0 - avg_diff
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def discontinuous_dimensions(other_event, threshold: 0.3)
|
|
29
|
+
DIMENSIONS.select do |dim|
|
|
30
|
+
(dimension_values[dim] - other_event.dimension_values[dim]).abs > threshold
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def to_h
|
|
35
|
+
{
|
|
36
|
+
content: content,
|
|
37
|
+
dimension_values: dimension_values,
|
|
38
|
+
created_at: created_at.iso8601
|
|
39
|
+
}
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
private
|
|
43
|
+
|
|
44
|
+
def build_dimension_values(values)
|
|
45
|
+
DIMENSIONS.to_h do |dim|
|
|
46
|
+
raw = values.fetch(dim, DEFAULT_DIMENSION_VALUE)
|
|
47
|
+
[dim, raw.clamp(0.0, 1.0)]
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Integration
|
|
9
|
+
module SituationModel
|
|
10
|
+
module Helpers
|
|
11
|
+
class SituationModel
|
|
12
|
+
include Constants
|
|
13
|
+
|
|
14
|
+
attr_reader :id, :label, :events, :current_state, :created_at, :last_updated_at
|
|
15
|
+
|
|
16
|
+
def initialize(label:)
|
|
17
|
+
@id = SecureRandom.uuid
|
|
18
|
+
@label = label
|
|
19
|
+
@events = []
|
|
20
|
+
@current_state = DIMENSIONS.to_h { |dim| [dim, DEFAULT_DIMENSION_VALUE] }
|
|
21
|
+
@created_at = Time.now.utc
|
|
22
|
+
@last_updated_at = Time.now.utc
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def add_event(event)
|
|
26
|
+
previous = events.last
|
|
27
|
+
events << event
|
|
28
|
+
@current_state = event.dimension_values.dup
|
|
29
|
+
@last_updated_at = Time.now.utc
|
|
30
|
+
previous ? event.continuity_with(previous) : 1.0
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def coherence
|
|
34
|
+
return 1.0 if events.size <= 1
|
|
35
|
+
|
|
36
|
+
pairs = events.each_cons(2).to_a
|
|
37
|
+
total = pairs.sum { |a, b| b.continuity_with(a) }
|
|
38
|
+
(total / pairs.size.to_f).clamp(COHERENCE_FLOOR, COHERENCE_CEILING)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def health_label
|
|
42
|
+
c = coherence
|
|
43
|
+
MODEL_HEALTH_LABELS.find { |range, _| range.cover?(c) }&.last || :collapsed
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def dominant_dimension
|
|
47
|
+
current_state.max_by { |_, v| v }&.first
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def weakest_dimension
|
|
51
|
+
current_state.min_by { |_, v| v }&.first
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def event_boundaries(threshold: 0.3)
|
|
55
|
+
indices = []
|
|
56
|
+
events.each_cons(2).with_index do |(a, b), idx|
|
|
57
|
+
indices << (idx + 1) unless b.discontinuous_dimensions(a, threshold: threshold).empty?
|
|
58
|
+
end
|
|
59
|
+
indices
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def dimension_trajectory(dimension)
|
|
63
|
+
events.map { |e| e.dimension_values[dimension] }
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def decay!
|
|
67
|
+
DIMENSIONS.each do |dim|
|
|
68
|
+
current_state[dim] = (current_state[dim] - DECAY_RATE).clamp(COHERENCE_FLOOR, COHERENCE_CEILING)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def to_h
|
|
73
|
+
{
|
|
74
|
+
id: id,
|
|
75
|
+
label: label,
|
|
76
|
+
event_count: events.size,
|
|
77
|
+
current_state: current_state,
|
|
78
|
+
coherence: coherence,
|
|
79
|
+
health_label: health_label,
|
|
80
|
+
created_at: created_at.iso8601,
|
|
81
|
+
last_updated_at: last_updated_at.iso8601
|
|
82
|
+
}
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module SituationModel
|
|
8
|
+
module Runners
|
|
9
|
+
module SituationModel
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
12
|
+
|
|
13
|
+
def create_situation_model(label:, **)
|
|
14
|
+
model = engine.create_model(label: label)
|
|
15
|
+
Legion::Logging.debug "[situation_model] create_model: id=#{model.id} label=#{label}"
|
|
16
|
+
{ success: true, model: model.to_h }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def add_situation_event(model_id:, content:, **opts)
|
|
20
|
+
dim_values = {
|
|
21
|
+
space: opts.fetch(:space, 0.5),
|
|
22
|
+
time: opts.fetch(:time, 0.5),
|
|
23
|
+
causation: opts.fetch(:causation, 0.5),
|
|
24
|
+
intentionality: opts.fetch(:intentionality, 0.5),
|
|
25
|
+
protagonist: opts.fetch(:protagonist, 0.5)
|
|
26
|
+
}
|
|
27
|
+
event = engine.add_event_to_model(model_id: model_id, content: content, dimension_values: dim_values)
|
|
28
|
+
unless event
|
|
29
|
+
Legion::Logging.debug "[situation_model] add_event: model_id=#{model_id} not found"
|
|
30
|
+
return { success: false, error: 'model not found' }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
coherence = engine.model_coherence(model_id: model_id)
|
|
34
|
+
Legion::Logging.debug "[situation_model] add_event: model_id=#{model_id} coherence=#{coherence.round(3)}"
|
|
35
|
+
{ success: true, event: event.to_h, coherence: coherence }
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def situation_model_coherence(model_id:, **)
|
|
39
|
+
coherence = engine.model_coherence(model_id: model_id)
|
|
40
|
+
Legion::Logging.debug "[situation_model] coherence: model_id=#{model_id} value=#{coherence}"
|
|
41
|
+
return { success: false, error: 'model not found' } if coherence.nil?
|
|
42
|
+
|
|
43
|
+
{ success: true, model_id: model_id, coherence: coherence }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def find_situation_boundaries(model_id:, threshold: 0.3, **)
|
|
47
|
+
boundaries = engine.find_boundaries(model_id: model_id, threshold: threshold)
|
|
48
|
+
Legion::Logging.debug "[situation_model] boundaries: model_id=#{model_id} count=#{boundaries&.size}"
|
|
49
|
+
return { success: false, error: 'model not found' } if boundaries.nil?
|
|
50
|
+
|
|
51
|
+
{ success: true, model_id: model_id, boundaries: boundaries, threshold: threshold }
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def situation_dimension_trajectory(model_id:, dimension:, **)
|
|
55
|
+
dim = dimension.to_sym
|
|
56
|
+
trajectory = engine.dimension_trajectory(model_id: model_id, dimension: dim)
|
|
57
|
+
Legion::Logging.debug "[situation_model] trajectory: model_id=#{model_id} dimension=#{dim} points=#{trajectory&.size}"
|
|
58
|
+
return { success: false, error: 'model not found' } if trajectory.nil?
|
|
59
|
+
|
|
60
|
+
{ success: true, model_id: model_id, dimension: dim, trajectory: trajectory }
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def most_coherent_situations(limit: 5, **)
|
|
64
|
+
models = engine.most_coherent(limit: limit)
|
|
65
|
+
Legion::Logging.debug "[situation_model] most_coherent: limit=#{limit} found=#{models.size}"
|
|
66
|
+
{ success: true, models: models.map(&:to_h), count: models.size }
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def situations_by_label(label:, **)
|
|
70
|
+
models = engine.models_by_label(label: label)
|
|
71
|
+
Legion::Logging.debug "[situation_model] by_label: label=#{label} found=#{models.size}"
|
|
72
|
+
{ success: true, label: label, models: models.map(&:to_h), count: models.size }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def update_situation_models(**)
|
|
76
|
+
engine.decay_all
|
|
77
|
+
pruned = engine.prune_collapsed
|
|
78
|
+
Legion::Logging.debug "[situation_model] update: decay_all pruned=#{pruned.size}"
|
|
79
|
+
{ success: true, pruned_count: pruned.size }
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def situation_model_stats(**)
|
|
83
|
+
stats = engine.to_h
|
|
84
|
+
Legion::Logging.debug "[situation_model] stats: model_count=#{stats[:model_count]}"
|
|
85
|
+
{ success: true, **stats }
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
private
|
|
89
|
+
|
|
90
|
+
def engine
|
|
91
|
+
@engine ||= Helpers::SituationEngine.new
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/integration/situation_model/version'
|
|
4
|
+
require 'legion/extensions/agentic/integration/situation_model/helpers/constants'
|
|
5
|
+
require 'legion/extensions/agentic/integration/situation_model/helpers/situation_event'
|
|
6
|
+
require 'legion/extensions/agentic/integration/situation_model/helpers/situation_model'
|
|
7
|
+
require 'legion/extensions/agentic/integration/situation_model/helpers/situation_engine'
|
|
8
|
+
require 'legion/extensions/agentic/integration/situation_model/runners/situation_model'
|
|
9
|
+
require 'legion/extensions/agentic/integration/situation_model/helpers/client'
|
|
10
|
+
require 'legion/extensions/agentic/integration/situation_model/client'
|
|
11
|
+
|
|
12
|
+
module Legion
|
|
13
|
+
module Extensions
|
|
14
|
+
module Agentic
|
|
15
|
+
module Integration
|
|
16
|
+
module SituationModel
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/integration/synthesis/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/integration/synthesis/helpers/synthesis_stream'
|
|
5
|
+
require 'legion/extensions/agentic/integration/synthesis/helpers/synthesis'
|
|
6
|
+
require 'legion/extensions/agentic/integration/synthesis/helpers/synthesis_engine'
|
|
7
|
+
require 'legion/extensions/agentic/integration/synthesis/runners/cognitive_synthesis'
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Agentic
|
|
12
|
+
module Integration
|
|
13
|
+
module Synthesis
|
|
14
|
+
class Client
|
|
15
|
+
include Runners::CognitiveSynthesis
|
|
16
|
+
|
|
17
|
+
def initialize(engine: nil, **)
|
|
18
|
+
@synthesis_engine = engine || Helpers::SynthesisEngine.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
attr_reader :synthesis_engine
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Integration
|
|
7
|
+
module Synthesis
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
MAX_STREAMS = 50
|
|
11
|
+
MAX_SYNTHESES = 200
|
|
12
|
+
DEFAULT_WEIGHT = 0.5
|
|
13
|
+
COHERENCE_THRESHOLD = 0.6
|
|
14
|
+
NOVELTY_THRESHOLD = 0.7
|
|
15
|
+
FRESHNESS_DECAY = 0.02
|
|
16
|
+
MIN_STREAMS_FOR_SYNTHESIS = 2
|
|
17
|
+
|
|
18
|
+
STREAM_TYPES = %i[emotional perceptual memorial predictive reasoning social identity motor].freeze
|
|
19
|
+
|
|
20
|
+
COHERENCE_LABELS = {
|
|
21
|
+
(0.8..) => :unified,
|
|
22
|
+
(0.6...0.8) => :coherent,
|
|
23
|
+
(0.4...0.6) => :fragmented,
|
|
24
|
+
(0.2...0.4) => :dissonant,
|
|
25
|
+
(..0.2) => :chaotic
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
CONFIDENCE_LABELS = {
|
|
29
|
+
(0.8..) => :certain,
|
|
30
|
+
(0.6...0.8) => :confident,
|
|
31
|
+
(0.4...0.6) => :uncertain,
|
|
32
|
+
(0.2...0.4) => :doubtful,
|
|
33
|
+
(..0.2) => :guessing
|
|
34
|
+
}.freeze
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Integration
|
|
9
|
+
module Synthesis
|
|
10
|
+
module Helpers
|
|
11
|
+
class Synthesis
|
|
12
|
+
include Constants
|
|
13
|
+
|
|
14
|
+
attr_reader :id, :streams, :coherence, :novelty, :confidence, :content, :created_at
|
|
15
|
+
|
|
16
|
+
def initialize(streams:, coherence:, novelty:, confidence:, content:)
|
|
17
|
+
@id = SecureRandom.uuid
|
|
18
|
+
@streams = streams
|
|
19
|
+
@coherence = coherence.clamp(0.0, 1.0)
|
|
20
|
+
@novelty = novelty.clamp(0.0, 1.0)
|
|
21
|
+
@confidence = confidence.clamp(0.0, 1.0)
|
|
22
|
+
@content = content
|
|
23
|
+
@created_at = Time.now.utc
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def fragmented?
|
|
27
|
+
@coherence < COHERENCE_THRESHOLD
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def novel?
|
|
31
|
+
@novelty > NOVELTY_THRESHOLD
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def coherence_label
|
|
35
|
+
COHERENCE_LABELS.find { |range, _| range.cover?(@coherence) }&.last || :chaotic
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def confidence_label
|
|
39
|
+
CONFIDENCE_LABELS.find { |range, _| range.cover?(@confidence) }&.last || :guessing
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def to_h
|
|
43
|
+
{
|
|
44
|
+
id: @id,
|
|
45
|
+
streams: @streams,
|
|
46
|
+
coherence: @coherence,
|
|
47
|
+
novelty: @novelty,
|
|
48
|
+
confidence: @confidence,
|
|
49
|
+
content: @content,
|
|
50
|
+
fragmented: fragmented?,
|
|
51
|
+
novel: novel?,
|
|
52
|
+
coherence_label: coherence_label,
|
|
53
|
+
confidence_label: confidence_label,
|
|
54
|
+
created_at: @created_at
|
|
55
|
+
}
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|