registry.py 848 B

123456789101112131415161718192021222324252627
  1. import os
  2. import yaml
  3. all_microagents = {}
  4. # Get the list of directories and sort them to preserve determinism
  5. dirs = sorted(os.listdir(os.path.dirname(__file__)))
  6. for dir in dirs:
  7. base = os.path.dirname(__file__) + '/' + dir
  8. if os.path.isfile(base):
  9. continue
  10. if dir.startswith('_'):
  11. continue
  12. promptFile = base + '/prompt.md'
  13. agentFile = base + '/agent.yaml'
  14. if not os.path.isfile(promptFile) or not os.path.isfile(agentFile):
  15. raise Exception(f'Missing prompt or agent file in {base}. Please create them.')
  16. with open(promptFile, 'r') as f:
  17. prompt = f.read()
  18. with open(agentFile, 'r') as f:
  19. agent = yaml.safe_load(f)
  20. if 'name' not in agent:
  21. raise Exception(f'Missing name in {agentFile}')
  22. agent['prompt'] = prompt
  23. all_microagents[agent['name']] = agent