Class: RailsAgents::Generators::AgentGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/rails_agents/agent/agent_generator.rb

Constant Summary collapse

RESERVED_SLUGS =
%w[shared library].freeze

Instance Method Summary collapse

Instance Method Details

#create_agent_directoryObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/rails_agents/agent/agent_generator.rb', line 25

def create_agent_directory
  if RESERVED_SLUGS.include?(file_name)
    raise Thor::Error,
      "Agent name #{file_name.inspect} is reserved for app/agents/shared/. Choose another name."
  end

  empty_directory agent_path
  empty_directory File.join(agent_path, "tools")
  empty_directory File.join(agent_path, "skills")
  empty_directory File.join(agent_path, "knowledge")
  empty_directory File.join(agent_path, "connectors")
  empty_directory File.join(agent_path, "plugins")
  empty_directory File.join(agent_path, "channels")
  empty_directory File.join(agent_path, "evals")
end

#create_agent_filesObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/rails_agents/agent/agent_generator.rb', line 41

def create_agent_files
  if attach_database?
    template "agent_database.rb.tt", File.join(agent_path, "agent.rb")
    template "prompt_database.md.tt", File.join(agent_path, "prompt.md")
    empty_directory File.join(agent_path, "knowledge", "sources")
    template "knowledge/sources/rails_database.yml.tt",
      File.join(agent_path, "knowledge", "sources", "rails_database.yml")
  else
    template "agent.rb.tt", File.join(agent_path, "agent.rb")
    template "prompt.md.tt", File.join(agent_path, "prompt.md")
  end
  template "memory.rb.tt", File.join(agent_path, "memory.rb")
  template "imports.yml.tt", File.join(agent_path, "imports.yml")
  template "channels/slack.rb.tt", File.join(agent_path, "channels/slack.rb")
  template "evals/smoke.yml.tt", File.join(agent_path, "evals/smoke.yml")
end