Class: RubynCode::Teams::AgentRegistry
- Inherits:
-
Object
- Object
- RubynCode::Teams::AgentRegistry
- 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
-
#active ⇒ Array<Hash>
Returns only active agents.
-
#forest ⇒ Array<Hash>
Returns the full agent tree starting from all root agents.
-
#initialize(manager:, mailbox:) ⇒ AgentRegistry
constructor
A new instance of AgentRegistry.
-
#lineage(agent_id) ⇒ Array<Teammate>
Returns lineage (ancestors) for a given agent.
-
#snapshot ⇒ Array<Hash>
Returns a snapshot of all registered agents with their status and unread message counts.
-
#status_report ⇒ String
Returns a formatted status report of all agents.
Constructor Details
#initialize(manager:, mailbox:) ⇒ AgentRegistry
Returns a new instance of AgentRegistry.
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
#active ⇒ Array<Hash>
Returns only active agents.
28 29 30 |
# File 'lib/rubyn_code/teams/agent_registry.rb', line 28 def active @manager.active_teammates.map { |t| agent_snapshot(t) } end |
#forest ⇒ Array<Hash>
Returns the full agent tree starting from all root agents.
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.
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 |
#snapshot ⇒ Array<Hash>
Returns a snapshot of all registered agents with their status and unread message counts.
21 22 23 |
# File 'lib/rubyn_code/teams/agent_registry.rb', line 21 def snapshot @manager.list.map { |t| agent_snapshot(t) } end |
#status_report ⇒ String
Returns a formatted status report of all agents.
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 |