lex-agentic-memory 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-memory.gemspec +30 -0
- data/lib/legion/extensions/agentic/memory/archaeology/client.rb +19 -0
- data/lib/legion/extensions/agentic/memory/archaeology/helpers/archaeology_engine.rb +184 -0
- data/lib/legion/extensions/agentic/memory/archaeology/helpers/artifact.rb +146 -0
- data/lib/legion/extensions/agentic/memory/archaeology/helpers/constants.rb +95 -0
- data/lib/legion/extensions/agentic/memory/archaeology/helpers/excavation_site.rb +97 -0
- data/lib/legion/extensions/agentic/memory/archaeology/runners/cognitive_archaeology.rb +86 -0
- data/lib/legion/extensions/agentic/memory/archaeology/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/archaeology.rb +22 -0
- data/lib/legion/extensions/agentic/memory/compression/client.rb +15 -0
- data/lib/legion/extensions/agentic/memory/compression/helpers/compression_engine.rb +145 -0
- data/lib/legion/extensions/agentic/memory/compression/helpers/constants.rb +44 -0
- data/lib/legion/extensions/agentic/memory/compression/helpers/information_chunk.rb +81 -0
- data/lib/legion/extensions/agentic/memory/compression/runners/cognitive_compression.rb +76 -0
- data/lib/legion/extensions/agentic/memory/compression/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/compression.rb +19 -0
- data/lib/legion/extensions/agentic/memory/echo/client.rb +19 -0
- data/lib/legion/extensions/agentic/memory/echo/helpers/constants.rb +57 -0
- data/lib/legion/extensions/agentic/memory/echo/helpers/echo.rb +95 -0
- data/lib/legion/extensions/agentic/memory/echo/helpers/echo_engine.rb +136 -0
- data/lib/legion/extensions/agentic/memory/echo/runners/cognitive_echo.rb +81 -0
- data/lib/legion/extensions/agentic/memory/echo/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/echo.rb +19 -0
- data/lib/legion/extensions/agentic/memory/echo_chamber/client.rb +19 -0
- data/lib/legion/extensions/agentic/memory/echo_chamber/helpers/chamber.rb +134 -0
- data/lib/legion/extensions/agentic/memory/echo_chamber/helpers/chamber_engine.rb +156 -0
- data/lib/legion/extensions/agentic/memory/echo_chamber/helpers/constants.rb +60 -0
- data/lib/legion/extensions/agentic/memory/echo_chamber/helpers/echo.rb +96 -0
- data/lib/legion/extensions/agentic/memory/echo_chamber/runners/cognitive_echo_chamber.rb +84 -0
- data/lib/legion/extensions/agentic/memory/echo_chamber/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/echo_chamber.rb +21 -0
- data/lib/legion/extensions/agentic/memory/episodic/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/memory/episodic/client.rb +25 -0
- data/lib/legion/extensions/agentic/memory/episodic/helpers/constants.rb +36 -0
- data/lib/legion/extensions/agentic/memory/episodic/helpers/episode.rb +104 -0
- data/lib/legion/extensions/agentic/memory/episodic/helpers/episodic_binding.rb +57 -0
- data/lib/legion/extensions/agentic/memory/episodic/helpers/episodic_store.rb +141 -0
- data/lib/legion/extensions/agentic/memory/episodic/runners/episodic_buffer.rb +108 -0
- data/lib/legion/extensions/agentic/memory/episodic/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/episodic.rb +20 -0
- data/lib/legion/extensions/agentic/memory/hologram/client.rb +23 -0
- data/lib/legion/extensions/agentic/memory/hologram/helpers/constants.rb +67 -0
- data/lib/legion/extensions/agentic/memory/hologram/helpers/hologram.rb +118 -0
- data/lib/legion/extensions/agentic/memory/hologram/helpers/hologram_engine.rb +117 -0
- data/lib/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment.rb +70 -0
- data/lib/legion/extensions/agentic/memory/hologram/runners/cognitive_hologram.rb +110 -0
- data/lib/legion/extensions/agentic/memory/hologram/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/hologram.rb +22 -0
- data/lib/legion/extensions/agentic/memory/immune_memory/client.rb +19 -0
- data/lib/legion/extensions/agentic/memory/immune_memory/helpers/constants.rb +84 -0
- data/lib/legion/extensions/agentic/memory/immune_memory/helpers/encounter.rb +54 -0
- data/lib/legion/extensions/agentic/memory/immune_memory/helpers/immune_memory_engine.rb +171 -0
- data/lib/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell.rb +97 -0
- data/lib/legion/extensions/agentic/memory/immune_memory/runners/cognitive_immune_memory.rb +76 -0
- data/lib/legion/extensions/agentic/memory/immune_memory/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/immune_memory.rb +20 -0
- data/lib/legion/extensions/agentic/memory/nostalgia/client.rb +31 -0
- data/lib/legion/extensions/agentic/memory/nostalgia/helpers/constants.rb +68 -0
- data/lib/legion/extensions/agentic/memory/nostalgia/helpers/nostalgia_engine.rb +148 -0
- data/lib/legion/extensions/agentic/memory/nostalgia/helpers/nostalgia_event.rb +44 -0
- data/lib/legion/extensions/agentic/memory/nostalgia/helpers/nostalgic_memory.rb +97 -0
- data/lib/legion/extensions/agentic/memory/nostalgia/runners/analysis.rb +61 -0
- data/lib/legion/extensions/agentic/memory/nostalgia/runners/recall.rb +60 -0
- data/lib/legion/extensions/agentic/memory/nostalgia/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/nostalgia.rb +21 -0
- data/lib/legion/extensions/agentic/memory/offloading/client.rb +29 -0
- data/lib/legion/extensions/agentic/memory/offloading/helpers/constants.rb +55 -0
- data/lib/legion/extensions/agentic/memory/offloading/helpers/external_store.rb +82 -0
- data/lib/legion/extensions/agentic/memory/offloading/helpers/offloaded_item.rb +65 -0
- data/lib/legion/extensions/agentic/memory/offloading/helpers/offloading_engine.rb +138 -0
- data/lib/legion/extensions/agentic/memory/offloading/runners/cognitive_offloading.rb +102 -0
- data/lib/legion/extensions/agentic/memory/offloading/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/offloading.rb +20 -0
- data/lib/legion/extensions/agentic/memory/paleontology/client.rb +19 -0
- data/lib/legion/extensions/agentic/memory/paleontology/helpers/constants.rb +69 -0
- data/lib/legion/extensions/agentic/memory/paleontology/helpers/excavation.rb +62 -0
- data/lib/legion/extensions/agentic/memory/paleontology/helpers/fossil.rb +125 -0
- data/lib/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine.rb +170 -0
- data/lib/legion/extensions/agentic/memory/paleontology/runners/cognitive_paleontology.rb +93 -0
- data/lib/legion/extensions/agentic/memory/paleontology/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/paleontology.rb +22 -0
- data/lib/legion/extensions/agentic/memory/palimpsest/client.rb +19 -0
- data/lib/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer.rb +81 -0
- data/lib/legion/extensions/agentic/memory/palimpsest/helpers/constants.rb +56 -0
- data/lib/legion/extensions/agentic/memory/palimpsest/helpers/palimpsest.rb +124 -0
- data/lib/legion/extensions/agentic/memory/palimpsest/helpers/palimpsest_engine.rb +117 -0
- data/lib/legion/extensions/agentic/memory/palimpsest/runners/cognitive_palimpsest.rb +105 -0
- data/lib/legion/extensions/agentic/memory/palimpsest/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/palimpsest.rb +21 -0
- data/lib/legion/extensions/agentic/memory/reserve/client.rb +19 -0
- data/lib/legion/extensions/agentic/memory/reserve/helpers/constants.rb +58 -0
- data/lib/legion/extensions/agentic/memory/reserve/helpers/pathway.rb +112 -0
- data/lib/legion/extensions/agentic/memory/reserve/helpers/reserve_engine.rb +163 -0
- data/lib/legion/extensions/agentic/memory/reserve/runners/cognitive_reserve.rb +92 -0
- data/lib/legion/extensions/agentic/memory/reserve/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/reserve.rb +19 -0
- data/lib/legion/extensions/agentic/memory/semantic/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/memory/semantic/client.rb +28 -0
- data/lib/legion/extensions/agentic/memory/semantic/helpers/concept.rb +101 -0
- data/lib/legion/extensions/agentic/memory/semantic/helpers/constants.rb +51 -0
- data/lib/legion/extensions/agentic/memory/semantic/helpers/knowledge_store.rb +145 -0
- data/lib/legion/extensions/agentic/memory/semantic/runners/semantic_memory.rb +94 -0
- data/lib/legion/extensions/agentic/memory/semantic/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/semantic.rb +20 -0
- data/lib/legion/extensions/agentic/memory/semantic_priming/client.rb +19 -0
- data/lib/legion/extensions/agentic/memory/semantic_priming/helpers/connection.rb +77 -0
- data/lib/legion/extensions/agentic/memory/semantic_priming/helpers/constants.rb +68 -0
- data/lib/legion/extensions/agentic/memory/semantic_priming/helpers/priming_network.rb +206 -0
- data/lib/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node.rb +81 -0
- data/lib/legion/extensions/agentic/memory/semantic_priming/runners/semantic_priming.rb +120 -0
- data/lib/legion/extensions/agentic/memory/semantic_priming/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/semantic_priming.rb +20 -0
- data/lib/legion/extensions/agentic/memory/semantic_satiation/client.rb +28 -0
- data/lib/legion/extensions/agentic/memory/semantic_satiation/helpers/concept.rb +82 -0
- data/lib/legion/extensions/agentic/memory/semantic_satiation/helpers/constants.rb +37 -0
- data/lib/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine.rb +103 -0
- data/lib/legion/extensions/agentic/memory/semantic_satiation/runners/semantic_satiation.rb +92 -0
- data/lib/legion/extensions/agentic/memory/semantic_satiation/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/semantic_satiation.rb +19 -0
- data/lib/legion/extensions/agentic/memory/source_monitoring/actors/decay.rb +31 -0
- data/lib/legion/extensions/agentic/memory/source_monitoring/client.rb +28 -0
- data/lib/legion/extensions/agentic/memory/source_monitoring/helpers/constants.rb +66 -0
- data/lib/legion/extensions/agentic/memory/source_monitoring/helpers/source_record.rb +94 -0
- data/lib/legion/extensions/agentic/memory/source_monitoring/helpers/source_tracker.rb +119 -0
- data/lib/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring.rb +95 -0
- data/lib/legion/extensions/agentic/memory/source_monitoring/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/source_monitoring.rb +19 -0
- data/lib/legion/extensions/agentic/memory/trace/actors/decay.rb +45 -0
- data/lib/legion/extensions/agentic/memory/trace/actors/tier_migration.rb +45 -0
- data/lib/legion/extensions/agentic/memory/trace/batch_decay.rb +44 -0
- data/lib/legion/extensions/agentic/memory/trace/client.rb +32 -0
- data/lib/legion/extensions/agentic/memory/trace/helpers/cache_store.rb +167 -0
- data/lib/legion/extensions/agentic/memory/trace/helpers/decay.rb +68 -0
- data/lib/legion/extensions/agentic/memory/trace/helpers/error_tracer.rb +94 -0
- data/lib/legion/extensions/agentic/memory/trace/helpers/store.rb +260 -0
- data/lib/legion/extensions/agentic/memory/trace/helpers/trace.rb +106 -0
- data/lib/legion/extensions/agentic/memory/trace/local_migrations/20260316000001_create_memory_traces.rb +31 -0
- data/lib/legion/extensions/agentic/memory/trace/local_migrations/20260316000002_create_memory_associations.rb +13 -0
- data/lib/legion/extensions/agentic/memory/trace/persistent_store.rb +94 -0
- data/lib/legion/extensions/agentic/memory/trace/quota.rb +55 -0
- data/lib/legion/extensions/agentic/memory/trace/runners/consolidation.rb +121 -0
- data/lib/legion/extensions/agentic/memory/trace/runners/traces.rb +105 -0
- data/lib/legion/extensions/agentic/memory/trace/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/trace.rb +54 -0
- data/lib/legion/extensions/agentic/memory/transfer/client.rb +28 -0
- data/lib/legion/extensions/agentic/memory/transfer/helpers/constants.rb +34 -0
- data/lib/legion/extensions/agentic/memory/transfer/helpers/domain_knowledge.rb +74 -0
- data/lib/legion/extensions/agentic/memory/transfer/helpers/transfer_engine.rb +188 -0
- data/lib/legion/extensions/agentic/memory/transfer/runners/transfer_learning.rb +77 -0
- data/lib/legion/extensions/agentic/memory/transfer/version.rb +13 -0
- data/lib/legion/extensions/agentic/memory/transfer.rb +19 -0
- data/lib/legion/extensions/agentic/memory/version.rb +11 -0
- data/lib/legion/extensions/agentic/memory.rb +35 -0
- data/spec/legion/extensions/agentic/memory/archaeology/client_spec.rb +38 -0
- data/spec/legion/extensions/agentic/memory/archaeology/cognitive_archaeology_spec.rb +7 -0
- data/spec/legion/extensions/agentic/memory/archaeology/helpers/archaeology_engine_spec.rb +165 -0
- data/spec/legion/extensions/agentic/memory/archaeology/helpers/artifact_spec.rb +196 -0
- data/spec/legion/extensions/agentic/memory/archaeology/helpers/constants_spec.rb +42 -0
- data/spec/legion/extensions/agentic/memory/archaeology/helpers/excavation_site_spec.rb +115 -0
- data/spec/legion/extensions/agentic/memory/archaeology/runners/cognitive_archaeology_spec.rb +96 -0
- data/spec/legion/extensions/agentic/memory/compression/helpers/compression_engine_spec.rb +138 -0
- data/spec/legion/extensions/agentic/memory/compression/helpers/constants_spec.rb +50 -0
- data/spec/legion/extensions/agentic/memory/compression/helpers/information_chunk_spec.rb +123 -0
- data/spec/legion/extensions/agentic/memory/compression/runners/cognitive_compression_spec.rb +80 -0
- data/spec/legion/extensions/agentic/memory/echo/client_spec.rb +20 -0
- data/spec/legion/extensions/agentic/memory/echo/cognitive_echo_spec.rb +7 -0
- data/spec/legion/extensions/agentic/memory/echo/helpers/echo_engine_spec.rb +152 -0
- data/spec/legion/extensions/agentic/memory/echo/helpers/echo_spec.rb +128 -0
- data/spec/legion/extensions/agentic/memory/echo/runners_spec.rb +80 -0
- data/spec/legion/extensions/agentic/memory/echo_chamber/client_spec.rb +84 -0
- data/spec/legion/extensions/agentic/memory/echo_chamber/helpers/chamber_engine_spec.rb +266 -0
- data/spec/legion/extensions/agentic/memory/echo_chamber/helpers/chamber_spec.rb +249 -0
- data/spec/legion/extensions/agentic/memory/echo_chamber/helpers/constants_spec.rb +130 -0
- data/spec/legion/extensions/agentic/memory/echo_chamber/helpers/echo_spec.rb +252 -0
- data/spec/legion/extensions/agentic/memory/echo_chamber/runners/cognitive_echo_chamber_spec.rb +185 -0
- data/spec/legion/extensions/agentic/memory/episodic/client_spec.rb +80 -0
- data/spec/legion/extensions/agentic/memory/episodic/episodic_buffer_spec.rb +15 -0
- data/spec/legion/extensions/agentic/memory/episodic/helpers/constants_spec.rb +86 -0
- data/spec/legion/extensions/agentic/memory/episodic/helpers/episode_spec.rb +188 -0
- data/spec/legion/extensions/agentic/memory/episodic/helpers/episodic_binding_spec.rb +114 -0
- data/spec/legion/extensions/agentic/memory/episodic/helpers/episodic_store_spec.rb +201 -0
- data/spec/legion/extensions/agentic/memory/episodic/runners/episodic_buffer_spec.rb +208 -0
- data/spec/legion/extensions/agentic/memory/hologram/client_spec.rb +89 -0
- data/spec/legion/extensions/agentic/memory/hologram/cognitive_hologram_spec.rb +39 -0
- data/spec/legion/extensions/agentic/memory/hologram/helpers/constants_spec.rb +143 -0
- data/spec/legion/extensions/agentic/memory/hologram/helpers/hologram_engine_spec.rb +268 -0
- data/spec/legion/extensions/agentic/memory/hologram/helpers/hologram_spec.rb +256 -0
- data/spec/legion/extensions/agentic/memory/hologram/helpers/holographic_fragment_spec.rb +213 -0
- data/spec/legion/extensions/agentic/memory/hologram/runners/cognitive_hologram_spec.rb +239 -0
- data/spec/legion/extensions/agentic/memory/immune_memory/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/memory/immune_memory/cognitive_immune_memory_spec.rb +7 -0
- data/spec/legion/extensions/agentic/memory/immune_memory/helpers/encounter_spec.rb +85 -0
- data/spec/legion/extensions/agentic/memory/immune_memory/helpers/immune_memory_engine_spec.rb +203 -0
- data/spec/legion/extensions/agentic/memory/immune_memory/helpers/memory_cell_spec.rb +190 -0
- data/spec/legion/extensions/agentic/memory/immune_memory/runners_spec.rb +83 -0
- data/spec/legion/extensions/agentic/memory/nostalgia/client_spec.rb +71 -0
- data/spec/legion/extensions/agentic/memory/nostalgia/helpers/constants_spec.rb +65 -0
- data/spec/legion/extensions/agentic/memory/nostalgia/helpers/nostalgia_engine_spec.rb +191 -0
- data/spec/legion/extensions/agentic/memory/nostalgia/helpers/nostalgia_event_spec.rb +59 -0
- data/spec/legion/extensions/agentic/memory/nostalgia/helpers/nostalgic_memory_spec.rb +134 -0
- data/spec/legion/extensions/agentic/memory/nostalgia/runners/analysis_spec.rb +97 -0
- data/spec/legion/extensions/agentic/memory/nostalgia/runners/recall_spec.rb +81 -0
- data/spec/legion/extensions/agentic/memory/offloading/client_spec.rb +30 -0
- data/spec/legion/extensions/agentic/memory/offloading/helpers/constants_spec.rb +71 -0
- data/spec/legion/extensions/agentic/memory/offloading/helpers/external_store_spec.rb +158 -0
- data/spec/legion/extensions/agentic/memory/offloading/helpers/offloaded_item_spec.rb +123 -0
- data/spec/legion/extensions/agentic/memory/offloading/helpers/offloading_engine_spec.rb +250 -0
- data/spec/legion/extensions/agentic/memory/offloading/runners/cognitive_offloading_spec.rb +194 -0
- data/spec/legion/extensions/agentic/memory/paleontology/client_spec.rb +27 -0
- data/spec/legion/extensions/agentic/memory/paleontology/cognitive_paleontology_spec.rb +7 -0
- data/spec/legion/extensions/agentic/memory/paleontology/helpers/constants_spec.rb +33 -0
- data/spec/legion/extensions/agentic/memory/paleontology/helpers/excavation_spec.rb +71 -0
- data/spec/legion/extensions/agentic/memory/paleontology/helpers/fossil_spec.rb +134 -0
- data/spec/legion/extensions/agentic/memory/paleontology/helpers/paleontology_engine_spec.rb +148 -0
- data/spec/legion/extensions/agentic/memory/paleontology/runners/cognitive_paleontology_spec.rb +89 -0
- data/spec/legion/extensions/agentic/memory/palimpsest/client_spec.rb +58 -0
- data/spec/legion/extensions/agentic/memory/palimpsest/helpers/belief_layer_spec.rb +150 -0
- data/spec/legion/extensions/agentic/memory/palimpsest/helpers/constants_spec.rb +63 -0
- data/spec/legion/extensions/agentic/memory/palimpsest/helpers/palimpsest_engine_spec.rb +164 -0
- data/spec/legion/extensions/agentic/memory/palimpsest/helpers/palimpsest_spec.rb +172 -0
- data/spec/legion/extensions/agentic/memory/palimpsest/runners/cognitive_palimpsest_spec.rb +165 -0
- data/spec/legion/extensions/agentic/memory/reserve/client_spec.rb +37 -0
- data/spec/legion/extensions/agentic/memory/reserve/helpers/pathway_spec.rb +165 -0
- data/spec/legion/extensions/agentic/memory/reserve/helpers/reserve_engine_spec.rb +196 -0
- data/spec/legion/extensions/agentic/memory/reserve/runners/cognitive_reserve_spec.rb +96 -0
- data/spec/legion/extensions/agentic/memory/semantic/client_spec.rb +35 -0
- data/spec/legion/extensions/agentic/memory/semantic/helpers/concept_spec.rb +119 -0
- data/spec/legion/extensions/agentic/memory/semantic/helpers/knowledge_store_spec.rb +140 -0
- data/spec/legion/extensions/agentic/memory/semantic/runners/semantic_memory_spec.rb +103 -0
- data/spec/legion/extensions/agentic/memory/semantic_priming/helpers/connection_spec.rb +98 -0
- data/spec/legion/extensions/agentic/memory/semantic_priming/helpers/priming_network_spec.rb +208 -0
- data/spec/legion/extensions/agentic/memory/semantic_priming/helpers/semantic_node_spec.rb +125 -0
- data/spec/legion/extensions/agentic/memory/semantic_priming/semantic_priming_spec.rb +7 -0
- data/spec/legion/extensions/agentic/memory/semantic_satiation/client_spec.rb +19 -0
- data/spec/legion/extensions/agentic/memory/semantic_satiation/helpers/concept_spec.rb +167 -0
- data/spec/legion/extensions/agentic/memory/semantic_satiation/helpers/constants_spec.rb +81 -0
- data/spec/legion/extensions/agentic/memory/semantic_satiation/helpers/satiation_engine_spec.rb +189 -0
- data/spec/legion/extensions/agentic/memory/semantic_satiation/runners/semantic_satiation_spec.rb +176 -0
- data/spec/legion/extensions/agentic/memory/source_monitoring/client_spec.rb +25 -0
- data/spec/legion/extensions/agentic/memory/source_monitoring/helpers/source_record_spec.rb +152 -0
- data/spec/legion/extensions/agentic/memory/source_monitoring/helpers/source_tracker_spec.rb +139 -0
- data/spec/legion/extensions/agentic/memory/source_monitoring/runners/source_monitoring_spec.rb +102 -0
- data/spec/legion/extensions/agentic/memory/trace/actors/decay_spec.rb +62 -0
- data/spec/legion/extensions/agentic/memory/trace/actors/tier_migration_spec.rb +62 -0
- data/spec/legion/extensions/agentic/memory/trace/batch_decay_spec.rb +26 -0
- data/spec/legion/extensions/agentic/memory/trace/client_spec.rb +62 -0
- data/spec/legion/extensions/agentic/memory/trace/helpers/decay_spec.rb +134 -0
- data/spec/legion/extensions/agentic/memory/trace/helpers/store_spec.rb +217 -0
- data/spec/legion/extensions/agentic/memory/trace/helpers/trace_spec.rb +120 -0
- data/spec/legion/extensions/agentic/memory/trace/local_persistence_spec.rb +255 -0
- data/spec/legion/extensions/agentic/memory/trace/memory_spec.rb +11 -0
- data/spec/legion/extensions/agentic/memory/trace/persistent_store_spec.rb +50 -0
- data/spec/legion/extensions/agentic/memory/trace/quota_spec.rb +56 -0
- data/spec/legion/extensions/agentic/memory/trace/runners/consolidation_spec.rb +118 -0
- data/spec/legion/extensions/agentic/memory/trace/runners/traces_spec.rb +69 -0
- data/spec/legion/extensions/agentic/memory/transfer/client_spec.rb +18 -0
- data/spec/legion/extensions/agentic/memory/transfer/helpers/constants_spec.rb +41 -0
- data/spec/legion/extensions/agentic/memory/transfer/helpers/domain_knowledge_spec.rb +134 -0
- data/spec/legion/extensions/agentic/memory/transfer/helpers/transfer_engine_spec.rb +299 -0
- data/spec/legion/extensions/agentic/memory/transfer/runners/transfer_learning_spec.rb +144 -0
- data/spec/spec_helper.rb +46 -0
- metadata +351 -0
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Palimpsest
|
|
8
|
+
module Runners
|
|
9
|
+
module CognitivePalimpsest
|
|
10
|
+
include Helpers::Constants
|
|
11
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
12
|
+
|
|
13
|
+
def create_palimpsest(topic:, domain: :unknown, engine: nil, **)
|
|
14
|
+
p = resolve_engine(engine).create(topic: topic, domain: domain)
|
|
15
|
+
return { success: false, reason: :limit_or_duplicate } unless p
|
|
16
|
+
|
|
17
|
+
{ success: true, id: p.id, topic: p.topic, domain: p.domain }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def overwrite_belief(topic:, content:, confidence: DEFAULT_CONFIDENCE,
|
|
21
|
+
author: :system, engine: nil, **)
|
|
22
|
+
layer = resolve_engine(engine).overwrite(
|
|
23
|
+
topic: topic,
|
|
24
|
+
content: content,
|
|
25
|
+
confidence: confidence,
|
|
26
|
+
author: author
|
|
27
|
+
)
|
|
28
|
+
return { success: false, reason: :limit_reached } unless layer
|
|
29
|
+
|
|
30
|
+
{ success: true, layer_id: layer.id, version: layer.version,
|
|
31
|
+
confidence: layer.confidence.round(4) }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def peek_through_belief(topic:, depth: 1, engine: nil, **)
|
|
35
|
+
layers = resolve_engine(engine).peek_through(topic: topic, depth: depth)
|
|
36
|
+
{ success: true, layers: layers, count: layers.size }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def erode_belief(topic:, rate: EROSION_RATE, engine: nil, **)
|
|
40
|
+
result = resolve_engine(engine).erode(topic: topic, rate: rate)
|
|
41
|
+
return { success: false, reason: :not_found } if result.nil?
|
|
42
|
+
|
|
43
|
+
{ success: true, topic: topic, confidence: result.round(4) }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def ghost_layers(topic:, engine: nil, **)
|
|
47
|
+
layers = resolve_engine(engine).ghost_layers_for(topic: topic)
|
|
48
|
+
{ success: true, layers: layers, count: layers.size }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def all_ghost_layers(engine: nil, **)
|
|
52
|
+
layers = resolve_engine(engine).all_ghost_layers
|
|
53
|
+
{ success: true, layers: layers, count: layers.size }
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def domain_archaeology(domain:, engine: nil, **)
|
|
57
|
+
layers = resolve_engine(engine).domain_archaeology(domain: domain)
|
|
58
|
+
{ success: true, layers: layers, count: layers.size }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def belief_drift(topic:, engine: nil, **)
|
|
62
|
+
result = resolve_engine(engine).belief_drift(topic: topic)
|
|
63
|
+
return { success: false, reason: :not_found } unless result
|
|
64
|
+
|
|
65
|
+
{ success: true }.merge(result)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def overwrite_frequency(topic:, engine: nil, **)
|
|
69
|
+
count = resolve_engine(engine).overwrite_frequency(topic: topic)
|
|
70
|
+
return { success: false, reason: :not_found } if count.nil?
|
|
71
|
+
|
|
72
|
+
{ success: true, topic: topic, overwrite_count: count }
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def most_rewritten(limit: 10, engine: nil, **)
|
|
76
|
+
palimpsests = resolve_engine(engine).most_rewritten(limit: limit)
|
|
77
|
+
{ success: true, palimpsests: palimpsests, count: palimpsests.size }
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def decay_all_ghosts(ghost_rate: GHOST_DECAY, engine: nil, **)
|
|
81
|
+
resolve_engine(engine).decay_all!(ghost_rate: ghost_rate)
|
|
82
|
+
{ success: true }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def palimpsest_report(engine: nil, **)
|
|
86
|
+
report = resolve_engine(engine).palimpsest_report
|
|
87
|
+
{ success: true }.merge(report)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
private
|
|
91
|
+
|
|
92
|
+
def resolve_engine(engine)
|
|
93
|
+
engine || default_engine
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def default_engine
|
|
97
|
+
@default_engine ||= Helpers::PalimpsestEngine.new
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'palimpsest/version'
|
|
4
|
+
require_relative 'palimpsest/helpers/constants'
|
|
5
|
+
require_relative 'palimpsest/helpers/belief_layer'
|
|
6
|
+
require_relative 'palimpsest/helpers/palimpsest_engine'
|
|
7
|
+
require_relative 'palimpsest/helpers/palimpsest'
|
|
8
|
+
require_relative 'palimpsest/runners/cognitive_palimpsest'
|
|
9
|
+
require_relative 'palimpsest/client'
|
|
10
|
+
|
|
11
|
+
module Legion
|
|
12
|
+
module Extensions
|
|
13
|
+
module Agentic
|
|
14
|
+
module Memory
|
|
15
|
+
module Palimpsest
|
|
16
|
+
# Sub-module for cognitive palimpsest: layered memory overwriting and recovery
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Reserve
|
|
8
|
+
class Client
|
|
9
|
+
include Runners::CognitiveReserve
|
|
10
|
+
|
|
11
|
+
def initialize(engine: nil)
|
|
12
|
+
@engine = engine
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Reserve
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
# Maximum tracked pathways
|
|
11
|
+
MAX_PATHWAYS = 100
|
|
12
|
+
|
|
13
|
+
# Maximum tracked compensations
|
|
14
|
+
MAX_COMPENSATIONS = 200
|
|
15
|
+
|
|
16
|
+
# Maximum event history
|
|
17
|
+
MAX_HISTORY = 300
|
|
18
|
+
|
|
19
|
+
# Default pathway capacity (0..1)
|
|
20
|
+
DEFAULT_CAPACITY = 1.0
|
|
21
|
+
|
|
22
|
+
# Capacity bounds
|
|
23
|
+
CAPACITY_FLOOR = 0.0
|
|
24
|
+
CAPACITY_CEILING = 1.0
|
|
25
|
+
|
|
26
|
+
# Threshold below which a pathway is considered degraded
|
|
27
|
+
DEGRADED_THRESHOLD = 0.5
|
|
28
|
+
|
|
29
|
+
# Threshold below which a pathway is considered failed
|
|
30
|
+
FAILED_THRESHOLD = 0.1
|
|
31
|
+
|
|
32
|
+
# Compensation efficiency — how much of lost capacity a backup restores
|
|
33
|
+
COMPENSATION_EFFICIENCY = 0.7
|
|
34
|
+
|
|
35
|
+
# Recovery rate per tick
|
|
36
|
+
RECOVERY_RATE = 0.02
|
|
37
|
+
|
|
38
|
+
# Decay rate for unused compensatory pathways
|
|
39
|
+
COMPENSATION_DECAY = 0.01
|
|
40
|
+
|
|
41
|
+
# Reserve levels based on overall reserve ratio
|
|
42
|
+
RESERVE_LABELS = {
|
|
43
|
+
(0.8..) => :robust,
|
|
44
|
+
(0.6...0.8) => :adequate,
|
|
45
|
+
(0.4...0.6) => :reduced,
|
|
46
|
+
(0.2...0.4) => :vulnerable,
|
|
47
|
+
(..0.2) => :critical
|
|
48
|
+
}.freeze
|
|
49
|
+
|
|
50
|
+
# Pathway states
|
|
51
|
+
PATHWAY_STATES = %i[healthy degraded compensating failed].freeze
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Reserve
|
|
8
|
+
module Helpers
|
|
9
|
+
class Pathway
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :id, :domain, :function, :capacity, :backup_ids,
|
|
13
|
+
:damage_count, :compensation_count, :created_at, :updated_at
|
|
14
|
+
|
|
15
|
+
def initialize(id:, function:, domain: :general, capacity: DEFAULT_CAPACITY)
|
|
16
|
+
@id = id
|
|
17
|
+
@function = function
|
|
18
|
+
@domain = domain
|
|
19
|
+
@capacity = capacity.clamp(CAPACITY_FLOOR, CAPACITY_CEILING)
|
|
20
|
+
@backup_ids = []
|
|
21
|
+
@damage_count = 0
|
|
22
|
+
@compensation_count = 0
|
|
23
|
+
@created_at = Time.now.utc
|
|
24
|
+
@updated_at = @created_at
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def damage(amount:)
|
|
28
|
+
@capacity = (@capacity - amount.abs).clamp(CAPACITY_FLOOR, CAPACITY_CEILING)
|
|
29
|
+
@damage_count += 1
|
|
30
|
+
@updated_at = Time.now.utc
|
|
31
|
+
self
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def recover(amount: RECOVERY_RATE)
|
|
35
|
+
@capacity = (@capacity + amount.abs).clamp(CAPACITY_FLOOR, CAPACITY_CEILING)
|
|
36
|
+
@updated_at = Time.now.utc
|
|
37
|
+
self
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def add_backup(pathway_id:)
|
|
41
|
+
return self if @backup_ids.include?(pathway_id)
|
|
42
|
+
|
|
43
|
+
@backup_ids << pathway_id
|
|
44
|
+
@updated_at = Time.now.utc
|
|
45
|
+
self
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def remove_backup(pathway_id:)
|
|
49
|
+
@backup_ids.delete(pathway_id)
|
|
50
|
+
@updated_at = Time.now.utc
|
|
51
|
+
self
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def compensate!
|
|
55
|
+
@compensation_count += 1
|
|
56
|
+
@updated_at = Time.now.utc
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def state
|
|
60
|
+
return :failed if @capacity <= FAILED_THRESHOLD
|
|
61
|
+
return :compensating if @capacity <= DEGRADED_THRESHOLD && !@backup_ids.empty?
|
|
62
|
+
return :degraded if @capacity <= DEGRADED_THRESHOLD
|
|
63
|
+
|
|
64
|
+
:healthy
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def healthy?
|
|
68
|
+
state == :healthy
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def degraded?
|
|
72
|
+
@capacity <= DEGRADED_THRESHOLD
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def failed?
|
|
76
|
+
@capacity <= FAILED_THRESHOLD
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
def effective_capacity(backup_capacities: [])
|
|
80
|
+
return @capacity if @capacity > DEGRADED_THRESHOLD || backup_capacities.empty?
|
|
81
|
+
|
|
82
|
+
deficit = DEGRADED_THRESHOLD - @capacity
|
|
83
|
+
compensation = backup_capacities.sum(0.0) * COMPENSATION_EFFICIENCY
|
|
84
|
+
(@capacity + [compensation, deficit].min).clamp(CAPACITY_FLOOR, CAPACITY_CEILING)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def redundancy
|
|
88
|
+
@backup_ids.size
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def to_h
|
|
92
|
+
{
|
|
93
|
+
id: @id,
|
|
94
|
+
function: @function,
|
|
95
|
+
domain: @domain,
|
|
96
|
+
capacity: @capacity.round(4),
|
|
97
|
+
state: state,
|
|
98
|
+
backup_count: @backup_ids.size,
|
|
99
|
+
backup_ids: @backup_ids.dup,
|
|
100
|
+
damage_count: @damage_count,
|
|
101
|
+
compensation_count: @compensation_count,
|
|
102
|
+
created_at: @created_at,
|
|
103
|
+
updated_at: @updated_at
|
|
104
|
+
}
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Reserve
|
|
8
|
+
module Helpers
|
|
9
|
+
class ReserveEngine
|
|
10
|
+
include Constants
|
|
11
|
+
|
|
12
|
+
attr_reader :pathways, :history
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
@pathways = {}
|
|
16
|
+
@pathway_count = 0
|
|
17
|
+
@history = []
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def add_pathway(function:, domain: :general, capacity: DEFAULT_CAPACITY)
|
|
21
|
+
return nil if @pathways.size >= MAX_PATHWAYS
|
|
22
|
+
|
|
23
|
+
@pathway_count += 1
|
|
24
|
+
pathway = Pathway.new(
|
|
25
|
+
id: :"path_#{@pathway_count}",
|
|
26
|
+
function: function,
|
|
27
|
+
domain: domain,
|
|
28
|
+
capacity: capacity
|
|
29
|
+
)
|
|
30
|
+
@pathways[pathway.id] = pathway
|
|
31
|
+
record_event(:add_pathway, pathway_id: pathway.id)
|
|
32
|
+
pathway
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def link_backup(primary_id:, backup_id:)
|
|
36
|
+
primary = @pathways[primary_id]
|
|
37
|
+
backup = @pathways[backup_id]
|
|
38
|
+
return nil unless primary && backup
|
|
39
|
+
|
|
40
|
+
primary.add_backup(pathway_id: backup_id)
|
|
41
|
+
record_event(:link_backup, primary_id: primary_id, backup_id: backup_id)
|
|
42
|
+
primary
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def damage_pathway(pathway_id:, amount:)
|
|
46
|
+
pathway = @pathways[pathway_id]
|
|
47
|
+
return nil unless pathway
|
|
48
|
+
|
|
49
|
+
pathway.damage(amount: amount)
|
|
50
|
+
activate_compensation(pathway) if pathway.degraded?
|
|
51
|
+
record_event(:damage, pathway_id: pathway_id, amount: amount, state: pathway.state)
|
|
52
|
+
pathway
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def recover_pathway(pathway_id:, amount: RECOVERY_RATE)
|
|
56
|
+
pathway = @pathways[pathway_id]
|
|
57
|
+
return nil unless pathway
|
|
58
|
+
|
|
59
|
+
pathway.recover(amount: amount)
|
|
60
|
+
record_event(:recover, pathway_id: pathway_id)
|
|
61
|
+
pathway
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def effective_capacity(pathway_id:)
|
|
65
|
+
pathway = @pathways[pathway_id]
|
|
66
|
+
return nil unless pathway
|
|
67
|
+
|
|
68
|
+
backup_caps = pathway.backup_ids.filter_map { |bid| @pathways[bid]&.capacity }
|
|
69
|
+
pathway.effective_capacity(backup_capacities: backup_caps)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def overall_reserve
|
|
73
|
+
return DEFAULT_CAPACITY if @pathways.empty?
|
|
74
|
+
|
|
75
|
+
caps = @pathways.values.map do |p|
|
|
76
|
+
backup_caps = p.backup_ids.filter_map { |bid| @pathways[bid]&.capacity }
|
|
77
|
+
p.effective_capacity(backup_capacities: backup_caps)
|
|
78
|
+
end
|
|
79
|
+
caps.sum / caps.size.to_f
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def reserve_label
|
|
83
|
+
ratio = overall_reserve
|
|
84
|
+
RESERVE_LABELS.find { |range, _| range.cover?(ratio) }&.last || :critical
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def degraded_pathways
|
|
88
|
+
@pathways.values.select(&:degraded?).map(&:to_h)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def failed_pathways
|
|
92
|
+
@pathways.values.select(&:failed?).map(&:to_h)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def healthy_pathways
|
|
96
|
+
@pathways.values.select(&:healthy?).map(&:to_h)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def domain_reserve(domain:)
|
|
100
|
+
relevant = @pathways.values.select { |p| p.domain == domain }
|
|
101
|
+
return DEFAULT_CAPACITY if relevant.empty?
|
|
102
|
+
|
|
103
|
+
caps = relevant.map do |p|
|
|
104
|
+
backup_caps = p.backup_ids.filter_map { |bid| @pathways[bid]&.capacity }
|
|
105
|
+
p.effective_capacity(backup_capacities: backup_caps)
|
|
106
|
+
end
|
|
107
|
+
caps.sum / caps.size.to_f
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def most_vulnerable(limit: 5)
|
|
111
|
+
@pathways.values
|
|
112
|
+
.sort_by(&:capacity)
|
|
113
|
+
.first(limit)
|
|
114
|
+
.map(&:to_h)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def most_redundant(limit: 5)
|
|
118
|
+
@pathways.values
|
|
119
|
+
.sort_by { |p| -p.redundancy }
|
|
120
|
+
.first(limit)
|
|
121
|
+
.map(&:to_h)
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def recover_all
|
|
125
|
+
@pathways.each_value { |p| p.recover unless p.failed? }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def to_h
|
|
129
|
+
{
|
|
130
|
+
pathway_count: @pathways.size,
|
|
131
|
+
overall_reserve: overall_reserve.round(4),
|
|
132
|
+
reserve_label: reserve_label,
|
|
133
|
+
healthy_count: @pathways.values.count(&:healthy?),
|
|
134
|
+
degraded_count: @pathways.values.count(&:degraded?),
|
|
135
|
+
failed_count: @pathways.values.count(&:failed?),
|
|
136
|
+
history_size: @history.size
|
|
137
|
+
}
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
private
|
|
141
|
+
|
|
142
|
+
def activate_compensation(pathway)
|
|
143
|
+
pathway.backup_ids.each do |backup_id|
|
|
144
|
+
backup = @pathways[backup_id]
|
|
145
|
+
next unless backup&.healthy?
|
|
146
|
+
|
|
147
|
+
pathway.compensate!
|
|
148
|
+
record_event(:compensate, pathway_id: pathway.id, backup_id: backup_id)
|
|
149
|
+
break
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
def record_event(type, **details)
|
|
154
|
+
@history << { type: type, at: Time.now.utc }.merge(details)
|
|
155
|
+
@history.shift while @history.size > MAX_HISTORY
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Reserve
|
|
8
|
+
module Runners
|
|
9
|
+
module CognitiveReserve
|
|
10
|
+
include Helpers::Constants
|
|
11
|
+
include Legion::Extensions::Helpers::Lex if defined?(Legion::Extensions::Helpers::Lex)
|
|
12
|
+
|
|
13
|
+
def add_cognitive_pathway(function:, domain: :general, capacity: DEFAULT_CAPACITY, **)
|
|
14
|
+
pathway = engine.add_pathway(function: function, domain: domain, capacity: capacity)
|
|
15
|
+
return { success: false, reason: :limit_reached } unless pathway
|
|
16
|
+
|
|
17
|
+
{ success: true, pathway_id: pathway.id, capacity: pathway.capacity }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def link_backup_pathway(primary_id:, backup_id:, **)
|
|
21
|
+
result = engine.link_backup(primary_id: primary_id, backup_id: backup_id)
|
|
22
|
+
return { success: false, reason: :not_found } unless result
|
|
23
|
+
|
|
24
|
+
{ success: true, primary_id: primary_id, backup_id: backup_id, backup_count: result.backup_ids.size }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def damage_cognitive_pathway(pathway_id:, amount:, **)
|
|
28
|
+
pathway = engine.damage_pathway(pathway_id: pathway_id, amount: amount)
|
|
29
|
+
return { success: false, reason: :not_found } unless pathway
|
|
30
|
+
|
|
31
|
+
{
|
|
32
|
+
success: true,
|
|
33
|
+
pathway_id: pathway_id,
|
|
34
|
+
capacity: pathway.capacity.round(4),
|
|
35
|
+
state: pathway.state,
|
|
36
|
+
effective_capacity: engine.effective_capacity(pathway_id: pathway_id)&.round(4)
|
|
37
|
+
}
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def recover_cognitive_pathway(pathway_id:, amount: RECOVERY_RATE, **)
|
|
41
|
+
pathway = engine.recover_pathway(pathway_id: pathway_id, amount: amount)
|
|
42
|
+
return { success: false, reason: :not_found } unless pathway
|
|
43
|
+
|
|
44
|
+
{ success: true, pathway_id: pathway_id, capacity: pathway.capacity.round(4), state: pathway.state }
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def cognitive_reserve_assessment(**)
|
|
48
|
+
{
|
|
49
|
+
success: true,
|
|
50
|
+
overall_reserve: engine.overall_reserve.round(4),
|
|
51
|
+
reserve_label: engine.reserve_label,
|
|
52
|
+
most_vulnerable: engine.most_vulnerable,
|
|
53
|
+
degraded: engine.degraded_pathways,
|
|
54
|
+
failed: engine.failed_pathways
|
|
55
|
+
}
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def domain_cognitive_reserve(domain:, **)
|
|
59
|
+
{
|
|
60
|
+
success: true,
|
|
61
|
+
domain: domain,
|
|
62
|
+
reserve: engine.domain_reserve(domain: domain).round(4),
|
|
63
|
+
pathway_count: engine.pathways.values.count { |p| p.domain == domain }
|
|
64
|
+
}
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def most_redundant_pathways(**)
|
|
68
|
+
pathways = engine.most_redundant
|
|
69
|
+
{ success: true, pathways: pathways, count: pathways.size }
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def update_cognitive_reserve(**)
|
|
73
|
+
engine.recover_all
|
|
74
|
+
{ success: true }.merge(engine.to_h)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def cognitive_reserve_stats(**)
|
|
78
|
+
{ success: true }.merge(engine.to_h)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
def engine
|
|
84
|
+
@engine ||= Helpers::ReserveEngine.new
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'reserve/version'
|
|
4
|
+
require_relative 'reserve/helpers/constants'
|
|
5
|
+
require_relative 'reserve/helpers/pathway'
|
|
6
|
+
require_relative 'reserve/helpers/reserve_engine'
|
|
7
|
+
require_relative 'reserve/runners/cognitive_reserve'
|
|
8
|
+
require_relative 'reserve/client'
|
|
9
|
+
|
|
10
|
+
module Legion
|
|
11
|
+
module Extensions
|
|
12
|
+
module Agentic
|
|
13
|
+
module Memory
|
|
14
|
+
module Reserve
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/actors/every'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Memory
|
|
9
|
+
module Semantic
|
|
10
|
+
module Actor
|
|
11
|
+
class Decay < Legion::Extensions::Actors::Every
|
|
12
|
+
def runner_class
|
|
13
|
+
Legion::Extensions::Agentic::Memory::Semantic::Runners::SemanticMemory
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def runner_function
|
|
17
|
+
'update_semantic_memory'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def time
|
|
21
|
+
300
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def run_now?
|
|
25
|
+
false
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def use_runner?
|
|
29
|
+
false
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def check_subtask?
|
|
33
|
+
false
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def generate_task?
|
|
37
|
+
false
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/memory/semantic/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/memory/semantic/helpers/concept'
|
|
5
|
+
require 'legion/extensions/agentic/memory/semantic/helpers/knowledge_store'
|
|
6
|
+
require 'legion/extensions/agentic/memory/semantic/runners/semantic_memory'
|
|
7
|
+
|
|
8
|
+
module Legion
|
|
9
|
+
module Extensions
|
|
10
|
+
module Agentic
|
|
11
|
+
module Memory
|
|
12
|
+
module Semantic
|
|
13
|
+
class Client
|
|
14
|
+
include Runners::SemanticMemory
|
|
15
|
+
|
|
16
|
+
def initialize(knowledge_store: nil, **)
|
|
17
|
+
@knowledge_store = knowledge_store || Helpers::KnowledgeStore.new
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
attr_reader :knowledge_store
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|