Class: RubyLLM::Agents::AgentRegistry

Inherits:
Object
  • Object
show all
Defined in:
app/services/ruby_llm/agents/agent_registry.rb

Overview

Service for discovering and listing available agents

Combines two sources to ensure complete agent discovery:

  1. File system - Classes inheriting from ApplicationAgent in app/agents/

  2. Execution history - Agent types that have execution records

This ensures visibility of both current agents and deleted agents that still have execution history.

Examples:

Getting all agent names

AgentRegistry.all #=> ["SearchAgent", "SummaryAgent"]

Getting detailed info

AgentRegistry.all_with_details.each do |agent|
  puts "#{agent[:name]}: #{agent[:execution_count]} executions"
end

Class Method Summary collapse

Class Method Details

.allArray<String>

Returns all unique agent type names

Returns:

  • (Array<String>)

    Sorted list of agent class names



28
29
30
# File 'app/services/ruby_llm/agents/agent_registry.rb', line 28

def all
  (file_system_agents + execution_agents).uniq.sort
end

.all_with_detailsArray<Hash>

Returns detailed info about all agents

Returns:

  • (Array<Hash>)

    Agent info hashes with configuration and stats



51
52
53
54
55
# File 'app/services/ruby_llm/agents/agent_registry.rb', line 51

def all_with_details
  all.map do |agent_type|
    build_agent_info(agent_type)
  end
end

.config_for(agent_class) ⇒ Hash

Extracts full configuration for an agent class

Combines base config with type-specific config for display.

Parameters:

  • agent_class (Class)

    The agent class

Returns:

  • (Hash)

    Configuration hash



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/services/ruby_llm/agents/agent_registry.rb', line 63

def config_for(agent_class)
  return {} unless agent_class

  base = {
    model: safe_call(agent_class, :model),
    version: safe_call(agent_class, :version),
    description: safe_call(agent_class, :description)
  }

  type = detect_agent_type(agent_class)
  config = base.merge(type_config_for(agent_class, type))

  # Include dashboard override metadata
  config[:overridable_fields] = safe_call(agent_class, :overridable_fields) || []
  config[:active_overrides] = safe_call(agent_class, :active_overrides) || {}
  config[:has_overrides] = config[:active_overrides].any?

  config
end

.exists?(agent_type) ⇒ Boolean

Checks if an agent class is currently defined

Parameters:

  • agent_type (String)

    The agent class name

Returns:

  • (Boolean)

    true if the class exists



44
45
46
# File 'app/services/ruby_llm/agents/agent_registry.rb', line 44

def exists?(agent_type)
  find(agent_type).present?
end

.find(agent_type) ⇒ Class?

Finds an agent class by type name

Parameters:

  • agent_type (String)

    The agent class name

Returns:

  • (Class, nil)

    The agent class, or nil if not found



36
37
38
# File 'app/services/ruby_llm/agents/agent_registry.rb', line 36

def find(agent_type)
  agent_type.safe_constantize
end