Module: Legion::Extensions::Agentic::Integration::GlobalWorkspace::Runners::GlobalWorkspace

Includes:
Helpers::Lex
Included in:
Client
Defined in:
lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb

Instance Method Summary collapse

Instance Method Details

#acknowledge_broadcast(subscriber_id:) ⇒ Object



57
58
59
60
61
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 57

def acknowledge_broadcast(subscriber_id:, **)
  log.debug("[global_workspace] acknowledge: subscriber=#{subscriber_id}")
  ack = workspace.acknowledge(subscriber_id: subscriber_id)
  { success: ack }
end

#broadcast_history(limit: 10) ⇒ Object



75
76
77
78
79
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 75

def broadcast_history(limit: 10, **)
  history = workspace.broadcast_history.last(limit.to_i).map(&:to_h)
  log.debug("[global_workspace] history: #{history.size} entries")
  { success: true, history: history, total: workspace.broadcast_history.size }
end

#current_broadcastObject



69
70
71
72
73
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 69

def current_broadcast(**)
  content = workspace.current_content
  log.debug("[global_workspace] current_broadcast: #{content ? 'active' : 'none'}")
  { success: true, broadcast: content }
end

#query_consciousness(content:) ⇒ Object



63
64
65
66
67
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 63

def query_consciousness(content:, **)
  is_conscious = workspace.conscious?(content)
  log.debug("[global_workspace] conscious?(#{content}): #{is_conscious}")
  { success: true, conscious: is_conscious }
end

#register_subscriber(id:, name:, domains: []) ⇒ Object



45
46
47
48
49
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 45

def register_subscriber(id:, name:, domains: [], **)
  log.debug("[global_workspace] register_subscriber: id=#{id} name=#{name}")
  registered = workspace.register_subscriber(id: id, name: name, domains: domains)
  { success: registered, subscriber_count: workspace.subscriber_count }
end

#run_competitionObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 30

def run_competition(**)
  log.debug('[global_workspace] run_competition')
  broadcast = workspace.compete
  if broadcast
    {
      success:   true,
      broadcast: broadcast.to_h,
      state:     workspace.state,
      remaining: workspace.competitor_count
    }
  else
    { success: false, reason: :no_winner, state: workspace.state, competitors: workspace.competitor_count }
  end
end

#submit_for_broadcast(content:, source:, domain:, salience:, coalition: []) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 13

def submit_for_broadcast(content:, source:, domain:, salience:, coalition: [], **)
  log.debug("[global_workspace] submit: source=#{source} domain=#{domain} salience=#{salience}")
  competitor = workspace.submit(
    content:   content,
    source:    source,
    domain:    domain,
    salience:  salience,
    coalition: coalition
  )
  if competitor
    { success: true, effective_salience: competitor.effective_salience.round(4),
      competitors: workspace.competitor_count }
  else
    { success: false, reason: :below_threshold, competitors: workspace.competitor_count }
  end
end

#unregister_subscriber(id:) ⇒ Object



51
52
53
54
55
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 51

def unregister_subscriber(id:, **)
  log.debug("[global_workspace] unregister_subscriber: id=#{id}")
  removed = workspace.unregister_subscriber(id: id)
  { success: removed, subscriber_count: workspace.subscriber_count }
end

#update_global_workspaceObject



81
82
83
84
85
86
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 81

def update_global_workspace(**)
  log.debug('[global_workspace] tick')
  workspace.tick
  { success: true, state: workspace.state, competitors: workspace.competitor_count,
    utilization: workspace.utilization.round(4) }
end

#workspace_statsObject



88
89
90
91
# File 'lib/legion/extensions/agentic/integration/global_workspace/runners/global_workspace.rb', line 88

def workspace_stats(**)
  log.debug('[global_workspace] stats')
  { success: true, stats: workspace.to_h }
end