Class: Agents::Registry
- Inherits:
-
Object
- Object
- Agents::Registry
- Defined in:
- lib/agents/registry.rb
Overview
Loads named agent definitions from Markdown files and provides lookup. Scans two directories:
1. Built-in agents shipped with Anima (agents/ in the gem root)
2. User-defined agents (~/.anima/agents/)
User agents override built-in ones when names collide.
Constant Summary collapse
- BUILTIN_DIR =
File.("../../agents", __dir__).freeze
- USER_DIR =
File.("~/.anima/agents").freeze
Instance Attribute Summary collapse
-
#agents ⇒ Hash{String => Definition}
readonly
Loaded definitions keyed by name.
Class Method Summary collapse
-
.instance ⇒ Registry
Returns the global registry, lazily loaded on first access.
-
.reload! ⇒ Registry
Reloads the global registry from disk.
Instance Method Summary collapse
- #any? ⇒ Boolean
-
#catalog ⇒ Hash{String => String}
Agent names and descriptions for inclusion in tool documentation.
-
#get(name) ⇒ Definition?
Looks up a named agent definition.
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
-
#load_all ⇒ self
Loads definitions from both built-in and user directories.
-
#load_directory(dir) ⇒ void
Loads agent definitions from a single directory.
-
#names ⇒ Array<String>
Registered agent names.
- #size ⇒ Integer
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
16 17 18 |
# File 'lib/agents/registry.rb', line 16 def initialize @agents = {} end |
Instance Attribute Details
#agents ⇒ Hash{String => Definition} (readonly)
Returns loaded definitions keyed by name.
11 12 13 |
# File 'lib/agents/registry.rb', line 11 def agents @agents end |
Class Method Details
.instance ⇒ Registry
Returns the global registry, lazily loaded on first access.
23 24 25 |
# File 'lib/agents/registry.rb', line 23 def self.instance @instance ||= new.load_all end |
.reload! ⇒ Registry
Reloads the global registry from disk.
30 31 32 |
# File 'lib/agents/registry.rb', line 30 def self.reload! @instance = new.load_all end |
Instance Method Details
#any? ⇒ Boolean
81 82 83 |
# File 'lib/agents/registry.rb', line 81 def any? @agents.any? end |
#catalog ⇒ Hash{String => String}
Agent names and descriptions for inclusion in tool documentation.
71 72 73 |
# File 'lib/agents/registry.rb', line 71 def catalog @agents.transform_values(&:description) end |
#get(name) ⇒ Definition?
Looks up a named agent definition.
64 65 66 |
# File 'lib/agents/registry.rb', line 64 def get(name) @agents[name] end |
#load_all ⇒ self
Loads definitions from both built-in and user directories. User definitions override built-in ones with the same name.
38 39 40 41 42 |
# File 'lib/agents/registry.rb', line 38 def load_all load_directory(BUILTIN_DIR) load_directory(USER_DIR) unless Rails.env.test? self end |
#load_directory(dir) ⇒ void
This method returns an undefined value.
Loads agent definitions from a single directory.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/agents/registry.rb', line 48 def load_directory(dir) return unless Dir.exist?(dir) Dir.glob(File.join(dir, "*.md")).sort.each do |path| definition = Definition.from_file(path) validate_tools!(definition.name, definition.tools) @agents[definition.name] = definition rescue InvalidDefinitionError => error warn "Skipping invalid agent definition #{path}: #{error.}" end end |
#names ⇒ Array<String>
Returns registered agent names.
76 77 78 |
# File 'lib/agents/registry.rb', line 76 def names @agents.keys end |
#size ⇒ Integer
86 87 88 |
# File 'lib/agents/registry.rb', line 86 def size @agents.size end |