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



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

def handle_mesh_departure(agent_id:)
  return nil unless Helpers::DataModels.apollo_expertise_available?

  sole_expert_domains = Helpers::DataModels.apollo_expertise
                                           .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



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

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: :observation,
    source_agent: agent_id,
    tags:         Array(insight[:tags])
  )
end

.publishable?(insight) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/legion/extensions/apollo/gaia_integration.rb', line 26

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