lex-apollo 0.3.4 → 0.3.5

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: e7d785a9fed9656eb22b307620a384f64e52646bca14728dc0de3ef2b1adb5bd
4
- data.tar.gz: c64bcf1b75ee0ed43a747722a610c5cee8de823995d5f7455e31ae5c9174c56d
3
+ metadata.gz: 6156122baf8989f96a09685918e8ed6f6608730c8e19e442a632f5faa8853ee7
4
+ data.tar.gz: 478d0003003a76abc6ffdc0c39a7be3b06d8e75f91e1c88a6edfa5e46a05634a
5
5
  SHA512:
6
- metadata.gz: 0ff89d33e4993dd8c71e392202c66add619ab04045fa674b5f8f0c4d891b727ca7401865d349c68bdc3a0344e1773db4f86651ed7e96ecbcaf0098a9d05cdbc9
7
- data.tar.gz: 29b69744b9870bee8e1fbfc030652aede63a51c3a12cd02a3bc69bfc805b6267cf8045346cb37dc2565e1e103ae6f3b559972536b02f3a62dd4b6f12223361a5
6
+ metadata.gz: 898147c2dbe69430a0dc4606db21a82100de37a1865b9d56157499530c7e7a205e8cc44cd39f23410293a8f3874c9dadacf9c5aa47c89bd5b61a7a39b9067951
7
+ data.tar.gz: 8ed9fe61c718b12abfd8b5b2c6a75e249e47491c6bf8068df984f6f18c8943ee5d3d56b3b2def551703b4cd7b0463942e20a4803a740ca7da65d25a87b90c344
@@ -130,6 +130,39 @@ module Legion
130
130
  { success: false, error: e.message }
131
131
  end
132
132
 
133
+ def redistribute_knowledge(agent_id:, min_confidence: 0.5, **)
134
+ return { success: false, error: 'apollo_data_not_available' } unless defined?(Legion::Data::Model::ApolloEntry)
135
+
136
+ entries = Legion::Data::Model::ApolloEntry
137
+ .where(source_agent: agent_id, status: 'confirmed')
138
+ .where { confidence > min_confidence }
139
+ .all
140
+
141
+ return { success: true, redistributed: 0 } if entries.empty?
142
+
143
+ store = (Legion::Extensions::Agentic::Memory::Trace.shared_store if defined?(Legion::Extensions::Agentic::Memory::Trace))
144
+
145
+ redistributed = 0
146
+ entries.each do |entry|
147
+ if store
148
+ trace = Legion::Extensions::Agentic::Memory::Trace::Helpers::Trace.new_trace(
149
+ type: :semantic,
150
+ content_payload: { content: entry.content, source_agent: agent_id,
151
+ content_type: entry.content_type, tags: Array(entry.tags) },
152
+ strength: entry.confidence.to_f,
153
+ domain_tag: Array(entry.tags).first || 'general'
154
+ )
155
+ store.store(trace)
156
+ end
157
+ redistributed += 1
158
+ end
159
+
160
+ Legion::Logging.info "[apollo] redistributed #{redistributed} entries from departing agent=#{agent_id}"
161
+ { success: true, redistributed: redistributed, agent_id: agent_id }
162
+ rescue Sequel::Error => e
163
+ { success: false, error: e.message }
164
+ end
165
+
133
166
  def retrieve_relevant(query: nil, limit: 5, min_confidence: 0.3, tags: nil, skip: false, **)
134
167
  return { status: :skipped } if skip
135
168
 
@@ -3,7 +3,7 @@
3
3
  module Legion
4
4
  module Extensions
5
5
  module Apollo
6
- VERSION = '0.3.4'
6
+ VERSION = '0.3.5'
7
7
  end
8
8
  end
9
9
  end
@@ -307,4 +307,88 @@ RSpec.describe Legion::Extensions::Apollo::Runners::Knowledge do
307
307
  end
308
308
  end
309
309
  end
310
+
311
+ describe '#redistribute_knowledge' do
312
+ let(:host) { Object.new.extend(described_class) }
313
+
314
+ context 'when Apollo data is not available' do
315
+ before { hide_const('Legion::Data::Model::ApolloEntry') if defined?(Legion::Data::Model::ApolloEntry) }
316
+
317
+ it 'returns a structured error' do
318
+ result = host.redistribute_knowledge(agent_id: 'agent-x')
319
+ expect(result[:success]).to be false
320
+ expect(result[:error]).to eq('apollo_data_not_available')
321
+ end
322
+ end
323
+
324
+ context 'when the departing agent has no confirmed entries' do
325
+ let(:mock_entry_class) { double('ApolloEntry') }
326
+
327
+ before do
328
+ stub_const('Legion::Data::Model::ApolloEntry', mock_entry_class)
329
+ chain = double('chain')
330
+ allow(mock_entry_class).to receive(:where).and_return(chain)
331
+ allow(chain).to receive(:where).and_return(double(all: []))
332
+ end
333
+
334
+ it 'returns success with zero redistributed' do
335
+ result = host.redistribute_knowledge(agent_id: 'departed-1')
336
+ expect(result[:success]).to be true
337
+ expect(result[:redistributed]).to eq(0)
338
+ end
339
+ end
340
+
341
+ context 'when the departing agent has confirmed entries' do
342
+ let(:mock_entry_class) { double('ApolloEntry') }
343
+ let(:mock_entry) do
344
+ double('entry', content: 'Ruby is fast', content_type: 'fact',
345
+ confidence: 0.8, tags: ['ruby'])
346
+ end
347
+
348
+ before do
349
+ stub_const('Legion::Data::Model::ApolloEntry', mock_entry_class)
350
+ chain = double('chain')
351
+ allow(mock_entry_class).to receive(:where).and_return(chain)
352
+ allow(chain).to receive(:where).and_return(double(all: [mock_entry]))
353
+ end
354
+
355
+ it 'returns the count of redistributed entries' do
356
+ result = host.redistribute_knowledge(agent_id: 'departed-2')
357
+ expect(result[:success]).to be true
358
+ expect(result[:redistributed]).to eq(1)
359
+ expect(result[:agent_id]).to eq('departed-2')
360
+ end
361
+
362
+ it 'stores into trace shared_store when Memory::Trace is available' do
363
+ mock_store = double('store')
364
+ mock_trace_helpers = Module.new do
365
+ def self.new_trace(type:, content_payload: nil, **kwargs) # rubocop:disable Lint/UnusedMethodArgument
366
+ { trace_id: 'trace-abc', trace_type: type, strength: kwargs[:strength] || 0.5 }
367
+ end
368
+ end
369
+ stub_const('Legion::Extensions::Agentic::Memory::Trace', Module.new)
370
+ stub_const('Legion::Extensions::Agentic::Memory::Trace::Helpers::Trace', mock_trace_helpers)
371
+ allow(Legion::Extensions::Agentic::Memory::Trace).to receive(:shared_store).and_return(mock_store)
372
+ allow(mock_store).to receive(:store)
373
+
374
+ result = host.redistribute_knowledge(agent_id: 'departed-3')
375
+ expect(result[:redistributed]).to eq(1)
376
+ expect(mock_store).to have_received(:store).once
377
+ end
378
+ end
379
+
380
+ context 'when Sequel raises an error' do
381
+ before do
382
+ stub_const('Legion::Data::Model::ApolloEntry', Class.new)
383
+ allow(Legion::Data::Model::ApolloEntry).to receive(:where)
384
+ .and_raise(Sequel::Error, 'db error')
385
+ end
386
+
387
+ it 'returns a structured error' do
388
+ result = host.redistribute_knowledge(agent_id: 'agent-x')
389
+ expect(result[:success]).to be false
390
+ expect(result[:error]).to eq('db error')
391
+ end
392
+ end
393
+ end
310
394
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lex-apollo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity