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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6156122baf8989f96a09685918e8ed6f6608730c8e19e442a632f5faa8853ee7
|
|
4
|
+
data.tar.gz: 478d0003003a76abc6ffdc0c39a7be3b06d8e75f91e1c88a6edfa5e46a05634a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
|
@@ -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
|