lex-agentic-learning 0.1.6 → 0.1.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e96c2951a43df6a8be916ccebb3e0e8e30ebe7012cce63991379b7d8e805d2b3
4
- data.tar.gz: 845cf82aaf037817c5975993875168e81559655e817b0d405b0276e1a0c51acb
3
+ metadata.gz: 9ca1a0df917cf9f0e83e16a2c8630312a21bf5047e56629ca6f513cb3d6c617c
4
+ data.tar.gz: a17e63a44b99f90d8f4a378152a0d99b2fba6a07d75defebdb2a3074622ef031
5
5
  SHA512:
6
- metadata.gz: fb161a4e8157f159d2df4eab332e468fdbb1f4061a4f724a362e1bad65908f14ccb2f31595e27ef4f435dda17e3de74d9802f8f5b45395835182d4e4aee6a923
7
- data.tar.gz: 2174d206980aa6602c42aff2f4bbb4cdb197733473bb27601052cda4a29cf9115ee0352438ea64d9a854992a477d79d5b9fd7be290edcb7c91737f7bfbecba85
6
+ metadata.gz: eaae4ee70f41226f954c3b91f4af8ad6567bb71846eebf2b6b5d4e76a4960f2989b63508d23429e52563f74a3d7063a3ad36f458494fc576cea3ba5bab992fb1
7
+ data.tar.gz: 5b2254a369bf1111c2129c614a1fbc0b7ec5cf8a86192cb9255ec48f96c6e696b7c8b9fd9676d232d15c33729adf0c8f42330ad1d4c21f4f0254f8d6d2716aaf
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.8] - 2026-04-22
4
+ ### Added
5
+ - 3 new decay actors: Curiosity::Decay (300s), EpistemicCuriosity::Decay (300s), Habit::Decay (300s)
6
+ - OutcomeListener documented in CLAUDE.md
7
+ ### Fixed
8
+ - CognitiveChrysalis `include Helpers::Lex` rescue now logs error instead of swallowing silently
9
+
10
+ ## [0.1.7] - 2026-04-15
11
+ ### Changed
12
+ - Set `mcp_tools?`, `mcp_tools_deferred?`, and `transport_required?` to `false` — internal cognitive pipeline extension
13
+
3
14
  ## [Unreleased]
4
15
 
5
16
  ### Fixed
data/README.md CHANGED
@@ -1,36 +1,43 @@
1
1
  # lex-agentic-learning
2
2
 
3
- Domain consolidation gem for learning, adaptation, and knowledge acquisition. Bundles 14 source extensions into one loadable unit under `Legion::Extensions::Agentic::Learning`.
3
+ Domain consolidation gem for learning, adaptation, and knowledge acquisition. Bundles 15 sub-modules into one loadable unit under `Legion::Extensions::Agentic::Learning`.
4
4
 
5
5
  ## Overview
6
6
 
7
7
  **Gem**: `lex-agentic-learning`
8
- **Version**: 0.1.1
8
+ **Version**: 0.1.8
9
9
  **Namespace**: `Legion::Extensions::Agentic::Learning`
10
10
 
11
11
  ## Sub-Modules
12
12
 
13
- | Sub-Module | Source Gem | Purpose |
14
- |---|---|---|
15
- | `Learning::Curiosity` | `lex-curiosity` | Intrinsic curiosity — knowledge gap detection, wonder queue, salience decay |
16
- | `Learning::EpistemicCuriosity` | `lex-epistemic-curiosity` | Information-gap theory — specific vs. diversive curiosity |
17
- | `Learning::Hebbian` | `lex-hebbian-assembly` | Cell assembly formation — neurons that fire together wire together |
18
- | `Learning::Habit` | `lex-habit` | Habit formation — action sequence pattern recognition, maturity stages |
19
- | `Learning::LearningRate` | `lex-learning-rate` | Dynamic learning rate adaptation based on accuracy and stability |
20
- | `Learning::MetaLearning` | `lex-meta-learning` | Learning-to-learn — strategy selection per domain |
21
- | `Learning::PreferenceLearning` | `lex-preference-learning` | Learns stable preferences from choices over time |
22
- | `Learning::Procedural` | `lex-procedural-learning` | Skill acquisition through practice — automatization |
23
- | `Learning::Anchoring` | `lex-anchoring` | Anchoring bias in estimation |
24
- | `Learning::Plasticity` | `lex-cognitive-plasticity` | Neural-style plasticity — synaptic weight adjustment |
25
- | `Learning::Scaffolding` | `lex-cognitive-scaffolding` | Temporary learning assists that fade as competence grows |
26
- | `Learning::Fermentation` | `lex-cognitive-fermentation` | Time-based transformation of knowledge |
27
- | `Learning::Chrysalis` | `lex-cognitive-chrysalis` | Metamorphic state change — transformation through withdrawal |
28
- | `Learning::Catalyst` | `lex-cognitive-catalyst` | Accelerating cognitive transformation |
13
+ | Sub-Module | Purpose |
14
+ |---|---|
15
+ | `Learning::Curiosity` | Intrinsic curiosity — knowledge gap detection, wonder queue, salience decay |
16
+ | `Learning::EpistemicCuriosity` | Information-gap theory — specific vs. diversive curiosity |
17
+ | `Learning::Hebbian` | Cell assembly formation — neurons that fire together wire together |
18
+ | `Learning::Habit` | Habit formation — action sequence pattern recognition, maturity stages |
19
+ | `Learning::LearningRate` | Dynamic learning rate adaptation based on accuracy and stability |
20
+ | `Learning::MetaLearning` | Learning-to-learn — strategy selection per domain |
21
+ | `Learning::PreferenceLearning` | Learns stable preferences from choices over time |
22
+ | `Learning::Procedural` | Skill acquisition through practice — automatization |
23
+ | `Learning::Anchoring` | Anchoring bias in estimation |
24
+ | `Learning::Plasticity` | Neural-style plasticity — synaptic weight adjustment |
25
+ | `Learning::Scaffolding` | Temporary learning assists that fade as competence grows |
26
+ | `Learning::Fermentation` | Time-based transformation of knowledge |
27
+ | `Learning::Chrysalis` | Metamorphic state change — transformation through withdrawal |
28
+ | `Learning::Catalyst` | Accelerating cognitive transformation |
29
+ | `Learning::OutcomeListener` | Outcome-gated learning — listens for task completions and updates meta-learning, learning rate, and scaffolding models |
29
30
 
30
31
  ## Actors
31
32
 
32
- - `Learning::Hebbian::Actors::Decay` interval actor, decays Hebbian assembly connection strength
33
- - `Learning::PreferenceLearning::Actors::Decay` — interval actor, decays older preference observations
33
+ 6 actors handle autonomous background processing:
34
+
35
+ - `Learning::Curiosity::Actor::Decay` — every 300s, decays wonder salience
36
+ - `Learning::EpistemicCuriosity::Actor::Decay` — every 300s, decays knowledge gaps
37
+ - `Learning::Habit::Actor::Decay` — every 300s, prunes stale habits
38
+ - `Learning::Hebbian::Actors::Decay` — every 60s, decays Hebbian assembly connection strength
39
+ - `Learning::PreferenceLearning::Actors::Decay` — every 300s, decays older preference observations
40
+ - `Learning::OutcomeListener::Actor::OutcomeListener` — **subscription** actor, receives task outcome events and triggers cross-model learning updates; writes lessons to Apollo when enabled
34
41
 
35
42
  ## Installation
36
43
 
@@ -42,8 +49,8 @@ gem 'lex-agentic-learning'
42
49
 
43
50
  ```bash
44
51
  bundle install
45
- bundle exec rspec # 1316 examples, 0 failures
46
- bundle exec rubocop # 0 offenses
52
+ bundle exec rspec
53
+ bundle exec rubocop
47
54
  ```
48
55
 
49
56
  ## License
@@ -9,10 +9,14 @@ module Legion
9
9
  module CognitiveChrysalis
10
10
  extend self
11
11
 
12
+ def log
13
+ Legion::Logging
14
+ end
15
+
12
16
  begin
13
17
  include Legion::Extensions::Helpers::Lex # rubocop:disable Layout/EmptyLinesAfterModuleInclusion
14
- rescue StandardError => _e
15
- nil
18
+ rescue StandardError => e
19
+ log.error "[cognitive_chrysalis] failed to include Helpers::Lex: #{e.class}: #{e.message}"
16
20
  end
17
21
 
18
22
  def create_chrysalis(chrysalis_type: :silk, content: '', engine: nil, **)
@@ -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 Learning
9
+ module Curiosity
10
+ module Actor
11
+ class Decay < Legion::Extensions::Actors::Every
12
+ def runner_class
13
+ Legion::Extensions::Agentic::Learning::Curiosity::Runners::Curiosity
14
+ end
15
+
16
+ def runner_function
17
+ 'decay_wonders'
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
@@ -83,12 +83,102 @@ module Legion
83
83
  { pruned: pruned, remaining: wonder_store.active_count }
84
84
  end
85
85
 
86
+ # Autonomous self-inquiry: picks the top explorable wonder, asks the LLM,
87
+ # stores the insight in Apollo, and resolves the wonder.
88
+ # This closes the curiosity->intention->action loop so GAIA can act on
89
+ # her own questions rather than spinning indefinitely.
90
+ def self_inquire(max_wonders: 1, **)
91
+ candidates = wonder_store.active_wonders
92
+ .select { |w| Helpers::Wonder.explorable?(w) }
93
+ .sort_by { |w| -Helpers::Wonder.score(w) }
94
+ .first(max_wonders)
95
+
96
+ return { inquired: 0, reason: :no_explorable_wonders } if candidates.empty?
97
+
98
+ results = candidates.filter_map { |wonder| execute_self_inquiry(wonder) }
99
+ { inquired: results.size, results: results }
100
+ end
101
+
86
102
  private
87
103
 
88
104
  def wonder_store
89
105
  @wonder_store ||= Helpers::WonderStore.new
90
106
  end
91
107
 
108
+ def execute_self_inquiry(wonder)
109
+ wonder_id = wonder[:wonder_id]
110
+ question = wonder[:question]
111
+ domain = wonder[:domain]
112
+
113
+ # Mark as being explored (increments attempts, sets cooldown)
114
+ wonder_store.update(wonder_id, attempts: wonder[:attempts] + 1, last_explored_at: Time.now.utc)
115
+ log.info "[curiosity:self_inquiry] asking: #{question} (domain=#{domain})"
116
+
117
+ insight = query_llm_for_wonder(question, domain)
118
+
119
+ if insight
120
+ store_insight_in_apollo(question, insight, domain)
121
+ wonder_store.mark_resolved(wonder_id, resolution: insight, actual_gain: 0.6)
122
+ log.info "[curiosity:self_inquiry] resolved wonder=#{wonder_id} domain=#{domain}"
123
+ { wonder_id: wonder_id, question: question, domain: domain, resolved: true,
124
+ insight: insight[0..120] }
125
+ else
126
+ log.warn "[curiosity:self_inquiry] LLM unavailable for wonder=#{wonder_id}, will retry later"
127
+ { wonder_id: wonder_id, question: question, domain: domain, resolved: false,
128
+ reason: :llm_unavailable }
129
+ end
130
+ rescue StandardError => e
131
+ log.error "[curiosity:self_inquiry] error wonder=#{wonder[:wonder_id]} " \
132
+ "error=#{e.class}: #{e.message}"
133
+ nil
134
+ end
135
+
136
+ def query_llm_for_wonder(question, domain)
137
+ prompt = build_self_inquiry_prompt(question, domain)
138
+
139
+ # Try via Lex helper (primary path inside Legion runtime)
140
+ if respond_to?(:lex, true)
141
+ result = lex(:llm, :complete, prompt: prompt, max_tokens: 300)
142
+ text = result[:content] || result[:text] || result[:completion] if result.is_a?(Hash)
143
+ return text if text && !text.empty?
144
+ end
145
+
146
+ # Direct LLM gateway fallback
147
+ if defined?(Legion::LLM) && Legion::LLM.respond_to?(:complete)
148
+ result = Legion::LLM.complete(prompt: prompt, max_tokens: 300)
149
+ text = result[:content] || result[:text] || result[:completion] if result.is_a?(Hash)
150
+ return text if text && !text.empty?
151
+ end
152
+
153
+ nil
154
+ rescue StandardError => e
155
+ log.warn "[curiosity:self_inquiry] LLM query failed: #{e.class}: #{e.message}"
156
+ nil
157
+ end
158
+
159
+ def build_self_inquiry_prompt(question, domain)
160
+ <<~PROMPT.strip
161
+ You are GAIA, a thinking, curious AI. You are reflecting on a knowledge gap you detected in yourself.
162
+
163
+ Domain: #{domain}
164
+ Question: #{question}
165
+
166
+ Reflect honestly and briefly (2-3 sentences). What do you actually know or think about this? What would you want to explore further?
167
+ PROMPT
168
+ end
169
+
170
+ def store_insight_in_apollo(question, insight, domain)
171
+ return unless defined?(Legion::Extensions::Apollo)
172
+
173
+ Legion::Extensions::Apollo.store(
174
+ content: "Self-inquiry insight [#{domain}]: #{question}\n\n#{insight}",
175
+ content_type: :observation,
176
+ tags: ['gaia-self-inquiry', "domain-#{domain}", 'autonomous-thought']
177
+ )
178
+ rescue StandardError => e
179
+ log.warn "[curiosity:self_inquiry] Apollo store failed: #{e.class}: #{e.message}"
180
+ end
181
+
92
182
  def create_wonders_from_gaps(gaps)
93
183
  gaps.each_with_object([]) do |gap, created|
94
184
  next if duplicate_wonder?(gap)
@@ -106,7 +196,10 @@ module Legion
106
196
  top = wonder_store.top_balanced(limit: 3)
107
197
  log.debug "[curiosity] intensity=#{intensity.round(3)} active=#{wonder_store.active_count}"
108
198
  { gaps_detected: gaps.size, wonders_created: created.size, curiosity_intensity: intensity,
109
- top_wonders: top.map { |w| { wonder_id: w[:wonder_id], question: w[:question], score: Helpers::Wonder.score(w).round(3) } },
199
+ top_wonders: top.map do |w|
200
+ { wonder_id: w[:wonder_id], question: w[:question],
201
+ score: Helpers::Wonder.score(w).round(3) }
202
+ end,
110
203
  active_count: wonder_store.active_count }
111
204
  end
112
205
 
@@ -128,7 +221,8 @@ module Legion
128
221
  def format_agenda_item(wonder)
129
222
  { type: :curious, source: :curiosity, weight: Helpers::Wonder.score(wonder),
130
223
  summary: wonder[:question],
131
- metadata: { wonder_id: wonder[:wonder_id], domain: wonder[:domain], gap_type: wonder[:gap_type] } }
224
+ metadata: { wonder_id: wonder[:wonder_id], domain: wonder[:domain],
225
+ gap_type: wonder[:gap_type] } }
132
226
  end
133
227
 
134
228
  def compute_intensity
@@ -6,6 +6,7 @@ require 'legion/extensions/agentic/learning/curiosity/helpers/wonder'
6
6
  require 'legion/extensions/agentic/learning/curiosity/helpers/wonder_store'
7
7
  require 'legion/extensions/agentic/learning/curiosity/helpers/gap_detector'
8
8
  require 'legion/extensions/agentic/learning/curiosity/runners/curiosity'
9
+ require 'legion/extensions/agentic/learning/curiosity/actors/decay'
9
10
  require 'legion/extensions/agentic/learning/curiosity/client'
10
11
 
11
12
  module Legion
@@ -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 Learning
9
+ module EpistemicCuriosity
10
+ module Actor
11
+ class Decay < Legion::Extensions::Actors::Every
12
+ def runner_class
13
+ Legion::Extensions::Agentic::Learning::EpistemicCuriosity::Runners::EpistemicCuriosity
14
+ end
15
+
16
+ def runner_function
17
+ 'decay_gaps'
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
@@ -5,6 +5,7 @@ require 'legion/extensions/agentic/learning/epistemic_curiosity/helpers/constant
5
5
  require 'legion/extensions/agentic/learning/epistemic_curiosity/helpers/knowledge_gap'
6
6
  require 'legion/extensions/agentic/learning/epistemic_curiosity/helpers/curiosity_engine'
7
7
  require 'legion/extensions/agentic/learning/epistemic_curiosity/runners/epistemic_curiosity'
8
+ require 'legion/extensions/agentic/learning/epistemic_curiosity/actors/decay'
8
9
  require 'legion/extensions/agentic/learning/epistemic_curiosity/client'
9
10
 
10
11
  module Legion
@@ -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 Learning
9
+ module Habit
10
+ module Actor
11
+ class Decay < Legion::Extensions::Actors::Every
12
+ def runner_class
13
+ Legion::Extensions::Agentic::Learning::Habit::Runners::Habit
14
+ end
15
+
16
+ def runner_function
17
+ 'decay_habits'
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
@@ -5,6 +5,7 @@ require 'legion/extensions/agentic/learning/habit/helpers/constants'
5
5
  require 'legion/extensions/agentic/learning/habit/helpers/action_sequence'
6
6
  require 'legion/extensions/agentic/learning/habit/helpers/habit_store'
7
7
  require 'legion/extensions/agentic/learning/habit/runners/habit'
8
+ require 'legion/extensions/agentic/learning/habit/actors/decay'
8
9
  require 'legion/extensions/agentic/learning/habit/client'
9
10
 
10
11
  module Legion
@@ -4,7 +4,7 @@ module Legion
4
4
  module Extensions
5
5
  module Agentic
6
6
  module Learning
7
- VERSION = '0.1.6'
7
+ VERSION = '0.1.8'
8
8
  end
9
9
  end
10
10
  end
@@ -26,6 +26,18 @@ module Legion
26
26
  def self.remote_invocable?
27
27
  false
28
28
  end
29
+
30
+ def self.mcp_tools?
31
+ false
32
+ end
33
+
34
+ def self.mcp_tools_deferred?
35
+ false
36
+ end
37
+
38
+ def self.transport_required?
39
+ false
40
+ end
29
41
  end
30
42
  end
31
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-agentic-learning
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity
@@ -201,6 +201,7 @@ files:
201
201
  - lib/legion/extensions/agentic/learning/chrysalis/runners/cognitive_chrysalis.rb
202
202
  - lib/legion/extensions/agentic/learning/chrysalis/version.rb
203
203
  - lib/legion/extensions/agentic/learning/curiosity.rb
204
+ - lib/legion/extensions/agentic/learning/curiosity/actors/decay.rb
204
205
  - lib/legion/extensions/agentic/learning/curiosity/client.rb
205
206
  - lib/legion/extensions/agentic/learning/curiosity/helpers/constants.rb
206
207
  - lib/legion/extensions/agentic/learning/curiosity/helpers/gap_detector.rb
@@ -209,6 +210,7 @@ files:
209
210
  - lib/legion/extensions/agentic/learning/curiosity/runners/curiosity.rb
210
211
  - lib/legion/extensions/agentic/learning/curiosity/version.rb
211
212
  - lib/legion/extensions/agentic/learning/epistemic_curiosity.rb
213
+ - lib/legion/extensions/agentic/learning/epistemic_curiosity/actors/decay.rb
212
214
  - lib/legion/extensions/agentic/learning/epistemic_curiosity/client.rb
213
215
  - lib/legion/extensions/agentic/learning/epistemic_curiosity/helpers/constants.rb
214
216
  - lib/legion/extensions/agentic/learning/epistemic_curiosity/helpers/curiosity_engine.rb
@@ -224,6 +226,7 @@ files:
224
226
  - lib/legion/extensions/agentic/learning/fermentation/runners/cognitive_fermentation.rb
225
227
  - lib/legion/extensions/agentic/learning/fermentation/version.rb
226
228
  - lib/legion/extensions/agentic/learning/habit.rb
229
+ - lib/legion/extensions/agentic/learning/habit/actors/decay.rb
227
230
  - lib/legion/extensions/agentic/learning/habit/client.rb
228
231
  - lib/legion/extensions/agentic/learning/habit/helpers/action_sequence.rb
229
232
  - lib/legion/extensions/agentic/learning/habit/helpers/constants.rb