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,148 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Nostalgia
|
|
8
|
+
module Helpers
|
|
9
|
+
class NostalgiaEngine
|
|
10
|
+
attr_reader :memories, :events
|
|
11
|
+
|
|
12
|
+
def initialize
|
|
13
|
+
@memories = []
|
|
14
|
+
@events = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def create_memory(content:, domain: :unknown, warmth: Constants::DEFAULT_WARMTH,
|
|
18
|
+
original_valence: 0.5)
|
|
19
|
+
memory = NostalgicMemory.new(
|
|
20
|
+
content: content,
|
|
21
|
+
domain: domain,
|
|
22
|
+
warmth: warmth,
|
|
23
|
+
original_valence: original_valence
|
|
24
|
+
)
|
|
25
|
+
@memories << memory
|
|
26
|
+
@memories.shift while @memories.size > Constants::MAX_MEMORIES
|
|
27
|
+
memory
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def trigger_nostalgia(trigger:, domain: nil, intensity_hint: nil)
|
|
31
|
+
candidates = find_candidates(domain, trigger)
|
|
32
|
+
return [] if candidates.empty?
|
|
33
|
+
|
|
34
|
+
new_events = candidates.map do |memory|
|
|
35
|
+
intensity = compute_intensity(memory, intensity_hint)
|
|
36
|
+
next unless intensity >= Constants::TRIGGER_SENSITIVITY
|
|
37
|
+
|
|
38
|
+
event = NostalgiaEvent.new(
|
|
39
|
+
memory_id: memory.id,
|
|
40
|
+
trigger: trigger,
|
|
41
|
+
intensity: intensity,
|
|
42
|
+
effect_on_mood: compute_mood_effect(memory, intensity)
|
|
43
|
+
)
|
|
44
|
+
memory.warm!(intensity * 0.1)
|
|
45
|
+
@events << event
|
|
46
|
+
event
|
|
47
|
+
end.compact
|
|
48
|
+
|
|
49
|
+
@events.shift while @events.size > Constants::MAX_EVENTS
|
|
50
|
+
new_events
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def age_all!
|
|
54
|
+
@memories.each(&:age!)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def warmth_by_domain
|
|
58
|
+
grouped = @memories.group_by(&:domain)
|
|
59
|
+
grouped.transform_values do |mems|
|
|
60
|
+
total = mems.sum(&:warmth)
|
|
61
|
+
(total / mems.size).round(10)
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def rosy_retrospection_index
|
|
66
|
+
return 0.0 if @memories.empty?
|
|
67
|
+
|
|
68
|
+
rosy_count = @memories.count(&:rosy?)
|
|
69
|
+
inflation_sum = @memories.select(&:rosy?).sum do |m|
|
|
70
|
+
m.warmth - m.original_valence
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
base = rosy_count.to_f / @memories.size
|
|
74
|
+
avg_inflation = rosy_count.positive? ? inflation_sum / rosy_count : 0.0
|
|
75
|
+
(base * avg_inflation).clamp(0.0, 1.0).round(10)
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def nostalgia_proneness
|
|
79
|
+
return 0.0 if @memories.empty?
|
|
80
|
+
|
|
81
|
+
avg_warmth = @memories.sum(&:warmth) / @memories.size
|
|
82
|
+
event_density = [@events.size.to_f / Constants::MAX_EVENTS, 1.0].min
|
|
83
|
+
((avg_warmth * 0.7) + (event_density * 0.3)).clamp(0.0, 1.0).round(10)
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def most_nostalgic_domains
|
|
87
|
+
warmth_by_domain.sort_by { |_, v| -v }.map do |domain, avg_warmth|
|
|
88
|
+
{ domain: domain, avg_warmth: avg_warmth.round(10) }
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def bittersweet_memories
|
|
93
|
+
@memories.select(&:bittersweet?).map(&:to_h)
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def nostalgia_report
|
|
97
|
+
index = rosy_retrospection_index
|
|
98
|
+
proneness = nostalgia_proneness
|
|
99
|
+
{
|
|
100
|
+
total_memories: @memories.size,
|
|
101
|
+
total_events: @events.size,
|
|
102
|
+
rosy_retrospection_index: index,
|
|
103
|
+
retrospection_label: Constants.label_for(Constants::RETROSPECTION_LABELS, index),
|
|
104
|
+
nostalgia_proneness: proneness,
|
|
105
|
+
nostalgia_label: Constants.label_for(Constants::NOSTALGIA_LABELS, proneness),
|
|
106
|
+
most_nostalgic_domains: most_nostalgic_domains,
|
|
107
|
+
bittersweet_count: bittersweet_memories.size,
|
|
108
|
+
rosy_count: @memories.count(&:rosy?)
|
|
109
|
+
}
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
private
|
|
113
|
+
|
|
114
|
+
def find_candidates(domain, trigger)
|
|
115
|
+
candidates = domain ? @memories.select { |m| m.domain == domain.to_sym } : @memories
|
|
116
|
+
return candidates.last(10) if trigger.nil?
|
|
117
|
+
|
|
118
|
+
by_content = candidates.select { |m| content_matches?(m.content, trigger) }
|
|
119
|
+
by_content.empty? ? candidates.last(5) : by_content
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
def content_matches?(content, trigger)
|
|
123
|
+
content.to_s.downcase.include?(trigger.to_s.downcase)
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def compute_intensity(memory, hint)
|
|
127
|
+
base = memory.warmth * 0.6
|
|
128
|
+
temporal_boost = [memory.temporal_distance / 1000.0, 0.3].min
|
|
129
|
+
hint_value = hint ? hint.clamp(0.0, 1.0) * 0.2 : 0.0
|
|
130
|
+
(base + temporal_boost + hint_value).clamp(0.0, 1.0).round(10)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def compute_mood_effect(memory, intensity)
|
|
134
|
+
if memory.bittersweet?
|
|
135
|
+
(intensity * 0.3).round(10)
|
|
136
|
+
elsif memory.rosy?
|
|
137
|
+
(intensity * 0.6).round(10)
|
|
138
|
+
else
|
|
139
|
+
(intensity * 0.4).round(10)
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Memory
|
|
9
|
+
module Nostalgia
|
|
10
|
+
module Helpers
|
|
11
|
+
class NostalgiaEvent
|
|
12
|
+
attr_reader :id, :memory_id, :trigger, :intensity, :effect_on_mood, :occurred_at
|
|
13
|
+
|
|
14
|
+
def initialize(memory_id:, trigger:, intensity:, effect_on_mood: 0.0)
|
|
15
|
+
@id = ::SecureRandom.uuid
|
|
16
|
+
@memory_id = memory_id
|
|
17
|
+
@trigger = trigger
|
|
18
|
+
@intensity = intensity.clamp(0.0, 1.0)
|
|
19
|
+
@effect_on_mood = effect_on_mood.clamp(-1.0, 1.0)
|
|
20
|
+
@occurred_at = Time.now.utc
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def nostalgia_label
|
|
24
|
+
Constants.label_for(Constants::NOSTALGIA_LABELS, @intensity)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def to_h
|
|
28
|
+
{
|
|
29
|
+
id: id,
|
|
30
|
+
memory_id: memory_id,
|
|
31
|
+
trigger: trigger,
|
|
32
|
+
intensity: @intensity,
|
|
33
|
+
nostalgia_label: nostalgia_label,
|
|
34
|
+
effect_on_mood: @effect_on_mood,
|
|
35
|
+
occurred_at: occurred_at
|
|
36
|
+
}
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
|
|
5
|
+
module Legion
|
|
6
|
+
module Extensions
|
|
7
|
+
module Agentic
|
|
8
|
+
module Memory
|
|
9
|
+
module Nostalgia
|
|
10
|
+
module Helpers
|
|
11
|
+
class NostalgicMemory
|
|
12
|
+
attr_reader :id, :content, :domain, :temporal_distance, :original_valence, :created_at
|
|
13
|
+
|
|
14
|
+
def initialize(content:, domain: :unknown, warmth: Constants::DEFAULT_WARMTH,
|
|
15
|
+
original_valence: 0.5)
|
|
16
|
+
@id = ::SecureRandom.uuid
|
|
17
|
+
@content = content
|
|
18
|
+
@domain = normalize_domain(domain)
|
|
19
|
+
@warmth = warmth.clamp(0.0, Constants::WARMTH_CEILING)
|
|
20
|
+
@original_valence = original_valence.clamp(0.0, 1.0)
|
|
21
|
+
@current_valence = @original_valence
|
|
22
|
+
@temporal_distance = 0
|
|
23
|
+
@created_at = Time.now.utc
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def warmth
|
|
27
|
+
@warmth.round(10)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def current_valence
|
|
31
|
+
@current_valence.round(10)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def age!
|
|
35
|
+
@temporal_distance += 1
|
|
36
|
+
growth = Constants::WARMTH_GROWTH * temporal_distance_factor
|
|
37
|
+
@warmth = (@warmth + growth).clamp(0.0, Constants::WARMTH_CEILING)
|
|
38
|
+
self
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def warm!(amount = Constants::WARMTH_GROWTH)
|
|
42
|
+
factor = 1.0 + (temporal_distance / 100.0)
|
|
43
|
+
@warmth = (@warmth + (amount.clamp(0.0, 1.0) * factor)).clamp(0.0, Constants::WARMTH_CEILING)
|
|
44
|
+
@current_valence = [@current_valence + (amount * 0.5), 1.0].min.round(10)
|
|
45
|
+
self
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def cool!(amount = Constants::WARMTH_DECAY)
|
|
49
|
+
@warmth = (@warmth - amount.clamp(0.0, 1.0)).clamp(0.0, Constants::WARMTH_CEILING)
|
|
50
|
+
self
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def rosy?
|
|
54
|
+
warmth > @original_valence
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def bittersweet?
|
|
58
|
+
warmth >= Constants::BITTERSWEET_THRESHOLD && @original_valence < Constants::BITTERSWEET_THRESHOLD
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def warmth_label
|
|
62
|
+
Constants.label_for(Constants::WARMTH_LABELS, warmth)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def to_h
|
|
66
|
+
{
|
|
67
|
+
id: id,
|
|
68
|
+
content: content,
|
|
69
|
+
domain: domain,
|
|
70
|
+
warmth: warmth,
|
|
71
|
+
warmth_label: warmth_label,
|
|
72
|
+
temporal_distance: temporal_distance,
|
|
73
|
+
original_valence: @original_valence,
|
|
74
|
+
current_valence: current_valence,
|
|
75
|
+
rosy: rosy?,
|
|
76
|
+
bittersweet: bittersweet?,
|
|
77
|
+
created_at: created_at
|
|
78
|
+
}
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
private
|
|
82
|
+
|
|
83
|
+
def normalize_domain(domain)
|
|
84
|
+
sym = domain.to_sym
|
|
85
|
+
Constants::MEMORY_DOMAINS.include?(sym) ? sym : :unknown
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def temporal_distance_factor
|
|
89
|
+
1.0 + (::Math.log(1 + @temporal_distance) * 0.1)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Nostalgia
|
|
8
|
+
module Runners
|
|
9
|
+
module Analysis
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
12
|
+
|
|
13
|
+
def warmth_by_domain(engine: nil, **)
|
|
14
|
+
eng = engine || nostalgia_engine
|
|
15
|
+
by_domain = eng.warmth_by_domain
|
|
16
|
+
Legion::Logging.debug "[cognitive_nostalgia] warmth_by_domain: #{by_domain.size} domains"
|
|
17
|
+
{ success: true, warmth_by_domain: by_domain }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def rosy_retrospection_index(engine: nil, **)
|
|
21
|
+
eng = engine || nostalgia_engine
|
|
22
|
+
index = eng.rosy_retrospection_index
|
|
23
|
+
label = Helpers::Constants.label_for(Helpers::Constants::RETROSPECTION_LABELS, index)
|
|
24
|
+
Legion::Logging.debug "[cognitive_nostalgia] rosy_retrospection_index=#{index.round(2)} label=#{label}"
|
|
25
|
+
{ success: true, index: index, label: label }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def nostalgia_proneness(engine: nil, **)
|
|
29
|
+
eng = engine || nostalgia_engine
|
|
30
|
+
proneness = eng.nostalgia_proneness
|
|
31
|
+
label = Helpers::Constants.label_for(Helpers::Constants::NOSTALGIA_LABELS, proneness)
|
|
32
|
+
Legion::Logging.debug "[cognitive_nostalgia] nostalgia_proneness=#{proneness.round(2)} label=#{label}"
|
|
33
|
+
{ success: true, proneness: proneness, label: label }
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def most_nostalgic_domains(engine: nil, **)
|
|
37
|
+
eng = engine || nostalgia_engine
|
|
38
|
+
domains = eng.most_nostalgic_domains
|
|
39
|
+
Legion::Logging.debug "[cognitive_nostalgia] most_nostalgic_domains: top=#{domains.first&.fetch(:domain, :none)}"
|
|
40
|
+
{ success: true, domains: domains }
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def bittersweet_memories(engine: nil, **)
|
|
44
|
+
eng = engine || nostalgia_engine
|
|
45
|
+
memories = eng.bittersweet_memories
|
|
46
|
+
Legion::Logging.debug "[cognitive_nostalgia] bittersweet_memories: count=#{memories.size}"
|
|
47
|
+
{ success: true, memories: memories, count: memories.size }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def nostalgia_engine
|
|
53
|
+
@nostalgia_engine ||= Helpers::NostalgiaEngine.new
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Nostalgia
|
|
8
|
+
module Runners
|
|
9
|
+
module Recall
|
|
10
|
+
include Legion::Extensions::Helpers::Lex if Legion::Extensions.const_defined?(:Helpers) &&
|
|
11
|
+
Legion::Extensions::Helpers.const_defined?(:Lex)
|
|
12
|
+
|
|
13
|
+
def store_memory(content:, domain: :unknown, warmth: Helpers::Constants::DEFAULT_WARMTH,
|
|
14
|
+
original_valence: 0.5, engine: nil, **)
|
|
15
|
+
eng = engine || nostalgia_engine
|
|
16
|
+
memory = eng.create_memory(
|
|
17
|
+
content: content,
|
|
18
|
+
domain: domain,
|
|
19
|
+
warmth: warmth,
|
|
20
|
+
original_valence: original_valence
|
|
21
|
+
)
|
|
22
|
+
Legion::Logging.debug "[cognitive_nostalgia] stored memory id=#{memory.id} domain=#{memory.domain} warmth=#{memory.warmth.round(2)}"
|
|
23
|
+
{ success: true, memory: memory.to_h }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def trigger_nostalgia(trigger:, domain: nil, intensity_hint: nil, engine: nil, **)
|
|
27
|
+
eng = engine || nostalgia_engine
|
|
28
|
+
events = eng.trigger_nostalgia(trigger: trigger, domain: domain, intensity_hint: intensity_hint)
|
|
29
|
+
Legion::Logging.debug "[cognitive_nostalgia] triggered nostalgia: trigger=#{trigger} events=#{events.size}"
|
|
30
|
+
{ success: true, events: events.map(&:to_h), count: events.size }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def age_memories(engine: nil, **)
|
|
34
|
+
eng = engine || nostalgia_engine
|
|
35
|
+
eng.age_all!
|
|
36
|
+
Legion::Logging.debug "[cognitive_nostalgia] aged #{eng.memories.size} memories"
|
|
37
|
+
{ success: true, memory_count: eng.memories.size }
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def nostalgia_report(engine: nil, **)
|
|
41
|
+
eng = engine || nostalgia_engine
|
|
42
|
+
report = eng.nostalgia_report
|
|
43
|
+
idx = report[:rosy_retrospection_index].round(2)
|
|
44
|
+
pro = report[:nostalgia_proneness].round(2)
|
|
45
|
+
Legion::Logging.debug "[cognitive_nostalgia] report: index=#{idx} proneness=#{pro}"
|
|
46
|
+
{ success: true, **report }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
|
|
51
|
+
def nostalgia_engine
|
|
52
|
+
@nostalgia_engine ||= Helpers::NostalgiaEngine.new
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'legion/extensions/agentic/memory/nostalgia/version'
|
|
4
|
+
require 'legion/extensions/agentic/memory/nostalgia/helpers/constants'
|
|
5
|
+
require 'legion/extensions/agentic/memory/nostalgia/helpers/nostalgic_memory'
|
|
6
|
+
require 'legion/extensions/agentic/memory/nostalgia/helpers/nostalgia_event'
|
|
7
|
+
require 'legion/extensions/agentic/memory/nostalgia/helpers/nostalgia_engine'
|
|
8
|
+
require 'legion/extensions/agentic/memory/nostalgia/runners/recall'
|
|
9
|
+
require 'legion/extensions/agentic/memory/nostalgia/runners/analysis'
|
|
10
|
+
require 'legion/extensions/agentic/memory/nostalgia/client'
|
|
11
|
+
|
|
12
|
+
module Legion
|
|
13
|
+
module Extensions
|
|
14
|
+
module Agentic
|
|
15
|
+
module Memory
|
|
16
|
+
module Nostalgia
|
|
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/memory/offloading/helpers/constants'
|
|
4
|
+
require 'legion/extensions/agentic/memory/offloading/helpers/external_store'
|
|
5
|
+
require 'legion/extensions/agentic/memory/offloading/helpers/offloaded_item'
|
|
6
|
+
require 'legion/extensions/agentic/memory/offloading/helpers/offloading_engine'
|
|
7
|
+
require 'legion/extensions/agentic/memory/offloading/runners/cognitive_offloading'
|
|
8
|
+
|
|
9
|
+
module Legion
|
|
10
|
+
module Extensions
|
|
11
|
+
module Agentic
|
|
12
|
+
module Memory
|
|
13
|
+
module Offloading
|
|
14
|
+
class Client
|
|
15
|
+
include Runners::CognitiveOffloading
|
|
16
|
+
|
|
17
|
+
def initialize(engine: nil, **)
|
|
18
|
+
@offloading_engine = engine || Helpers::OffloadingEngine.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
attr_reader :offloading_engine
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Legion
|
|
4
|
+
module Extensions
|
|
5
|
+
module Agentic
|
|
6
|
+
module Memory
|
|
7
|
+
module Offloading
|
|
8
|
+
module Helpers
|
|
9
|
+
module Constants
|
|
10
|
+
MAX_ITEMS = 500
|
|
11
|
+
MAX_STORES = 50
|
|
12
|
+
DEFAULT_STORE_TRUST = 0.7
|
|
13
|
+
TRUST_DECAY = 0.02
|
|
14
|
+
TRUST_BOOST = 0.05
|
|
15
|
+
|
|
16
|
+
ITEM_TYPES = %i[
|
|
17
|
+
fact procedure plan context delegation reminder calculation reference
|
|
18
|
+
].freeze
|
|
19
|
+
|
|
20
|
+
STORE_TYPES = %i[
|
|
21
|
+
database file agent tool memory_aid external_service notes
|
|
22
|
+
].freeze
|
|
23
|
+
|
|
24
|
+
TRUST_LABELS = {
|
|
25
|
+
(0.8..) => :highly_trusted,
|
|
26
|
+
(0.6...0.8) => :trusted,
|
|
27
|
+
(0.4...0.6) => :cautious,
|
|
28
|
+
(0.2...0.4) => :distrusted,
|
|
29
|
+
(..0.2) => :unreliable
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
32
|
+
IMPORTANCE_LABELS = {
|
|
33
|
+
(0.8..) => :critical,
|
|
34
|
+
(0.6...0.8) => :important,
|
|
35
|
+
(0.4...0.6) => :moderate,
|
|
36
|
+
(0.2...0.4) => :low,
|
|
37
|
+
(..0.2) => :trivial
|
|
38
|
+
}.freeze
|
|
39
|
+
|
|
40
|
+
OFFLOAD_LABELS = {
|
|
41
|
+
(0.8..) => :heavily_offloaded,
|
|
42
|
+
(0.6...0.8) => :mostly_offloaded,
|
|
43
|
+
(0.4...0.6) => :balanced,
|
|
44
|
+
(0.2...0.4) => :mostly_internal,
|
|
45
|
+
(..0.2) => :self_reliant
|
|
46
|
+
}.freeze
|
|
47
|
+
|
|
48
|
+
RETRIEVAL_SUCCESS_THRESHOLD = 0.7
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
require_relative 'constants'
|
|
5
|
+
|
|
6
|
+
module Legion
|
|
7
|
+
module Extensions
|
|
8
|
+
module Agentic
|
|
9
|
+
module Memory
|
|
10
|
+
module Offloading
|
|
11
|
+
module Helpers
|
|
12
|
+
class ExternalStore
|
|
13
|
+
include Constants
|
|
14
|
+
|
|
15
|
+
attr_reader :id, :name, :store_type, :trust, :items_stored,
|
|
16
|
+
:successful_retrievals, :failed_retrievals, :created_at
|
|
17
|
+
|
|
18
|
+
def initialize(name:, store_type:)
|
|
19
|
+
@id = ::SecureRandom.uuid
|
|
20
|
+
@name = name
|
|
21
|
+
@store_type = store_type
|
|
22
|
+
@trust = DEFAULT_STORE_TRUST
|
|
23
|
+
@items_stored = 0
|
|
24
|
+
@successful_retrievals = 0
|
|
25
|
+
@failed_retrievals = 0
|
|
26
|
+
@created_at = Time.now.utc
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def increment_items!
|
|
30
|
+
@items_stored += 1
|
|
31
|
+
self
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def record_success!
|
|
35
|
+
@successful_retrievals += 1
|
|
36
|
+
@trust = (@trust + TRUST_BOOST).clamp(0.0, 1.0).round(10)
|
|
37
|
+
self
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def record_failure!
|
|
41
|
+
@failed_retrievals += 1
|
|
42
|
+
@trust = (@trust - TRUST_DECAY).clamp(0.0, 1.0).round(10)
|
|
43
|
+
self
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def retrieval_rate
|
|
47
|
+
total = @successful_retrievals + @failed_retrievals
|
|
48
|
+
return 0.0 if total.zero?
|
|
49
|
+
|
|
50
|
+
(@successful_retrievals.to_f / total).round(10)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def reliable?
|
|
54
|
+
@trust >= RETRIEVAL_SUCCESS_THRESHOLD
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def trust_label
|
|
58
|
+
TRUST_LABELS.find { |range, _| range.cover?(@trust) }&.last || :unreliable
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def to_h
|
|
62
|
+
{
|
|
63
|
+
id: @id,
|
|
64
|
+
name: @name,
|
|
65
|
+
store_type: @store_type,
|
|
66
|
+
trust: @trust.round(10),
|
|
67
|
+
trust_label: trust_label,
|
|
68
|
+
items_stored: @items_stored,
|
|
69
|
+
successful_retrievals: @successful_retrievals,
|
|
70
|
+
failed_retrievals: @failed_retrievals,
|
|
71
|
+
retrieval_rate: retrieval_rate,
|
|
72
|
+
reliable: reliable?,
|
|
73
|
+
created_at: @created_at
|
|
74
|
+
}
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'securerandom'
|
|
4
|
+
require_relative 'constants'
|
|
5
|
+
|
|
6
|
+
module Legion
|
|
7
|
+
module Extensions
|
|
8
|
+
module Agentic
|
|
9
|
+
module Memory
|
|
10
|
+
module Offloading
|
|
11
|
+
module Helpers
|
|
12
|
+
class OffloadedItem
|
|
13
|
+
include Constants
|
|
14
|
+
|
|
15
|
+
attr_reader :id, :content, :item_type, :importance, :store_id,
|
|
16
|
+
:offloaded_at, :retrieved_count, :last_retrieved_at
|
|
17
|
+
|
|
18
|
+
def initialize(content:, item_type:, importance:, store_id:)
|
|
19
|
+
@id = ::SecureRandom.uuid
|
|
20
|
+
@content = content
|
|
21
|
+
@item_type = item_type
|
|
22
|
+
@importance = importance.clamp(0.0, 1.0)
|
|
23
|
+
@store_id = store_id
|
|
24
|
+
@offloaded_at = Time.now.utc
|
|
25
|
+
@retrieved_count = 0
|
|
26
|
+
@last_retrieved_at = nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def retrieve!
|
|
30
|
+
@retrieved_count += 1
|
|
31
|
+
@last_retrieved_at = Time.now.utc
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def stale?(threshold_seconds: 3600)
|
|
36
|
+
return false if @last_retrieved_at.nil? && @retrieved_count.zero?
|
|
37
|
+
|
|
38
|
+
reference = @last_retrieved_at || @offloaded_at
|
|
39
|
+
(Time.now.utc - reference) > threshold_seconds
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def importance_label
|
|
43
|
+
IMPORTANCE_LABELS.find { |range, _| range.cover?(@importance) }&.last || :trivial
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def to_h
|
|
47
|
+
{
|
|
48
|
+
id: @id,
|
|
49
|
+
content: @content,
|
|
50
|
+
item_type: @item_type,
|
|
51
|
+
importance: @importance.round(10),
|
|
52
|
+
importance_label: importance_label,
|
|
53
|
+
store_id: @store_id,
|
|
54
|
+
offloaded_at: @offloaded_at,
|
|
55
|
+
retrieved_count: @retrieved_count,
|
|
56
|
+
last_retrieved_at: @last_retrieved_at
|
|
57
|
+
}
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|