Module: Legion::Extensions::Agentic::Social::Social::Runners::Social

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

Instance Method Summary collapse

Instance Method Details

#agent_reputation(agent_id:) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 51

def agent_reputation(agent_id:, **)
  rep = social_graph.reputation_for(agent_id)
  return { error: 'unknown agent' } unless rep

  log.debug "[social] reputation for #{agent_id}: #{rep[:composite]}"
  rep
end

#group_status(group_id:) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 79

def group_status(group_id:, **)
  return { error: 'unknown group' } unless social_graph.groups.key?(group_id)

  group = social_graph.groups[group_id]
  {
    group_id:       group_id,
    role:           group[:role],
    members:        group[:members].size,
    cohesion:       group[:cohesion].round(4),
    cohesion_level: social_graph.classify_cohesion(group_id),
    violations:     group[:violations].size
  }
end

#join_group(group_id:, role: :contributor, members: []) ⇒ Object



30
31
32
33
34
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 30

def join_group(group_id:, role: :contributor, members: [], **)
  group = social_graph.join_group(group_id: group_id, role: role, members: members)
  log.info "[social] joined group=#{group_id} role=#{role}"
  { success: true, group_id: group_id, role: role, group: group }
end

#leave_group(group_id:) ⇒ Object



36
37
38
39
40
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 36

def leave_group(group_id:, **)
  social_graph.leave_group(group_id)
  log.info "[social] left group=#{group_id}"
  { success: true, group_id: group_id }
end

#reciprocity_status(agent_id:) ⇒ Object



59
60
61
62
63
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 59

def reciprocity_status(agent_id:, **)
  balance = social_graph.reciprocity_balance(agent_id)
  log.debug "[social] reciprocity #{agent_id}: #{balance}"
  balance
end

#record_exchange(agent_id:, action:, direction:) ⇒ Object



65
66
67
68
69
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 65

def record_exchange(agent_id:, action:, direction:, **)
  social_graph.record_reciprocity(agent_id: agent_id, action: action, direction: direction.to_sym)
  log.debug "[social] exchange agent=#{agent_id} dir=#{direction}"
  { success: true }
end

#report_violation(group_id:, type:, agent_id:) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 71

def report_violation(group_id:, type:, agent_id:, **)
  violation = social_graph.record_violation(group_id: group_id, type: type.to_sym, agent_id: agent_id)
  return { success: false, error: 'invalid group or violation type' } unless violation

  log.warn "[social] violation: #{type} by #{agent_id} in #{group_id}"
  { success: true, violation: violation, cohesion: social_graph.group_cohesion(group_id)&.round(4) }
end

#social_statsObject



99
100
101
102
103
104
105
106
107
108
109
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 99

def social_stats(**)
  log.debug '[social] stats'

  {
    groups:         social_graph.group_count,
    agents_tracked: social_graph.agents_tracked,
    standing:       social_graph.social_standing,
    ledger_size:    social_graph.reciprocity_ledger.size,
    group_roles:    social_graph.groups.transform_values { |g| g[:role] }
  }
end

#social_statusObject



93
94
95
96
97
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 93

def social_status(**)
  state = social_graph.to_h
  log.debug "[social] status: #{state[:social_standing]}"
  state
end

#update_reputation(agent_id:, dimension:, signal:) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/legion/extensions/agentic/social/social/runners/social.rb', line 42

def update_reputation(agent_id:, dimension:, signal:, **)
  result = social_graph.update_reputation(agent_id: agent_id, dimension: dimension.to_sym, signal: signal)
  return { success: false, error: 'invalid dimension' } unless result

  rep = social_graph.reputation_for(agent_id)
  log.debug "[social] reputation updated agent=#{agent_id} dim=#{dimension}"
  { success: true, reputation: rep }
end

#update_social(tick_results: {}, human_observations: []) ⇒ Object



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

def update_social(tick_results: {}, human_observations: [], **)
  social_graph.clear_reputation_changes!
  extract_social_signals(tick_results)
  process_human_observations(human_observations)

  log.debug "[social] groups=#{social_graph.group_count} " \
            "agents=#{social_graph.agents_tracked} standing=#{social_graph.social_standing}"

  {
    groups:             social_graph.group_count,
    agents_tracked:     social_graph.agents_tracked,
    standing:           social_graph.social_standing,
    ledger_size:        social_graph.reciprocity_ledger.size,
    reputation_updates: build_reputation_updates
  }
end