Class: RubynCode::Teams::AgentRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/teams/agent_registry.rb

Overview

Discovery service for active agents in the system.

Provides a unified view of all agents (main loop, sub-agents, teammates) with status, lineage, and messaging capabilities.

Instance Method Summary collapse

Constructor Details

#initialize(manager:, mailbox:) ⇒ AgentRegistry

Returns a new instance of AgentRegistry.

Parameters:

  • manager (Manager)

    the teammate manager

  • mailbox (Mailbox)

    the team mailbox



12
13
14
15
# File 'lib/rubyn_code/teams/agent_registry.rb', line 12

def initialize(manager:, mailbox:)
  @manager = manager
  @mailbox = mailbox
end

Instance Method Details

#activeArray<Hash>

Returns only active agents.

Returns:

  • (Array<Hash>)

    active agent snapshots



28
29
30
# File 'lib/rubyn_code/teams/agent_registry.rb', line 28

def active
  @manager.active_teammates.map { |t| agent_snapshot(t) }
end

#forestArray<Hash>

Returns the full agent tree starting from all root agents.

Returns:

  • (Array<Hash>)

    nested tree structures



35
36
37
# File 'lib/rubyn_code/teams/agent_registry.rb', line 35

def forest
  @manager.roots.map { |root| build_display_tree(root) }
end

#lineage(agent_id) ⇒ Array<Teammate>

Returns lineage (ancestors) for a given agent.

Parameters:

  • agent_id (String)

    the agent’s ID

Returns:

  • (Array<Teammate>)

    ordered from root to immediate parent



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubyn_code/teams/agent_registry.rb', line 43

def lineage(agent_id)
  ancestors = []
  current = @manager.find_by_id(agent_id)
  return ancestors unless current

  while current&.parent_agent_id
    parent = @manager.find_by_id(current.parent_agent_id)
    break unless parent

    ancestors.unshift(parent)
    current = parent
  end

  ancestors
end

#snapshotArray<Hash>

Returns a snapshot of all registered agents with their status and unread message counts.

Returns:

  • (Array<Hash>)

    agent snapshots



21
22
23
# File 'lib/rubyn_code/teams/agent_registry.rb', line 21

def snapshot
  @manager.list.map { |t| agent_snapshot(t) }
end

#status_reportString

Returns a formatted status report of all agents.

Returns:

  • (String)

    human-readable status report



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/rubyn_code/teams/agent_registry.rb', line 62

def status_report
  agents = snapshot
  return 'No agents registered.' if agents.empty?

  lines = ['Agent Registry Status:', '']
  agents.each do |agent|
    icon = status_icon(agent[:status])
    parent_info = agent[:parent_agent_id] ? " (child of #{agent[:parent_agent_id][0, 8]})" : ' (root)'
    lines << "  #{icon} #{agent[:name]} [#{agent[:role]}] — #{agent[:status]}#{parent_info}"
    lines << "    Unread: #{agent[:unread_count]}" if agent[:unread_count].positive?
  end
  lines.join("\n")
end