Module: Legion::Extensions::Apollo::GaiaIntegration

Defined in:
lib/legion/extensions/apollo/gaia_integration.rb

Constant Summary collapse

PUBLISH_CONFIDENCE_THRESHOLD =
0.6
PUBLISH_NOVELTY_THRESHOLD =
0.3

Class Method Summary collapse

Class Method Details

.handle_mesh_departure(agent_id:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/legion/extensions/apollo/gaia_integration.rb', line 29

def handle_mesh_departure(agent_id:)
  return nil unless defined?(Legion::Data::Model::ApolloExpertise)

  sole_expert_domains = Legion::Data::Model::ApolloExpertise
                        .where(agent_id: agent_id)
                        .all
                        .select { |e| sole_expert?(e.domain, agent_id) }
                        .map(&:domain)

  return nil if sole_expert_domains.empty?

  {
    event:           'knowledge_vulnerability',
    agent_id:        agent_id,
    domains_at_risk: sole_expert_domains,
    severity:        sole_expert_domains.size > 3 ? :critical : :warning
  }
end

.publish_insight(insight, agent_id:) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/legion/extensions/apollo/gaia_integration.rb', line 11

def publish_insight(insight, agent_id:)
  return nil unless publishable?(insight)
  return nil unless defined?(Legion::Extensions::Apollo::Client)

  client = Legion::Extensions::Apollo::Client.new(agent_id: agent_id)
  client.store_knowledge(
    content:      insight[:content],
    content_type: insight[:domain] || 'general',
    source_agent: agent_id,
    tags:         Array(insight[:tags])
  )
end

.publishable?(insight) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
# File 'lib/legion/extensions/apollo/gaia_integration.rb', line 24

def publishable?(insight)
  (insight[:confidence] || 0) > PUBLISH_CONFIDENCE_THRESHOLD &&
    (insight[:novelty] || 0) > PUBLISH_NOVELTY_THRESHOLD
end