Class: SmartAgent::Engine
- Inherits:
-
Object
- Object
- SmartAgent::Engine
- Defined in:
- lib/smart_agent/engine.rb
Class Method Summary collapse
Instance Method Summary collapse
- #agents ⇒ Object
- #build_agent(name, tools: nil, mcp_servers: nil) ⇒ Object
- #create_dir(filename) ⇒ Object
-
#initialize(config_file) ⇒ Engine
constructor
A new instance of Engine.
- #load_agents ⇒ Object
- #load_config(config_file) ⇒ Object
- #load_mcp_server ⇒ Object
- #load_tools ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Engine
Returns a new instance of Engine.
3 4 5 6 7 |
# File 'lib/smart_agent/engine.rb', line 3 def initialize(config_file) @config_file = config_file load_config(config_file) SmartAgent.logger.info "Started create the SmartAgent engine." end |
Class Method Details
.agents ⇒ Object
74 75 76 |
# File 'lib/smart_agent/engine.rb', line 74 def self.agents @agents ||= {} end |
Instance Method Details
#agents ⇒ Object
70 71 72 |
# File 'lib/smart_agent/engine.rb', line 70 def agents self.class.agents end |
#build_agent(name, tools: nil, mcp_servers: nil) ⇒ Object
65 66 67 68 |
# File 'lib/smart_agent/engine.rb', line 65 def build_agent(name, tools: nil, mcp_servers: nil) agent = Agent.new(name, tools: tools, mcp_servers: mcp_servers) agents[name] = agent end |
#create_dir(filename) ⇒ Object
9 10 11 12 13 |
# File 'lib/smart_agent/engine.rb', line 9 def create_dir(filename) path = File::path(filename).to_s parent_dir = File::dirname(path) Dir.mkdir(parent_dir, 0755) unless File.directory?(parent_dir) end |
#load_agents ⇒ Object
59 60 61 62 63 |
# File 'lib/smart_agent/engine.rb', line 59 def load_agents Dir.glob(File.join(@config["agent_path"], "*.rb")).each do |file| require(file) end end |
#load_config(config_file) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/smart_agent/engine.rb', line 15 def load_config(config_file) begin @config_file = config_file @config = YAML.load_file(config_file) if @config["logger_file"] create_dir(@config["logger_file"]) SmartAgent.logger = Logger.new(@config["logger_file"]) end if engine_config = @config["engine_config"] SmartAgent.prompt_engine = SmartPrompt::Engine.new(engine_config) else SmartAgent.logger.error "SmartPrompt Config file not found: #{ex.}" raise ConfigurationError, "SmartPrompt Config file not found: #{ex.}" end load_tools load_mcp_server load_agents SmartAgent.logger.info "Loading configuration from file: #{config_file}" rescue Psych::SyntaxError => ex SmartAgent.logger.error "YAML syntax error in config file: #{ex.}" raise ConfigurationError, "Invalid YAML syntax in config file: #{ex.}" rescue Errno::ENOENT => ex SmartAgent.logger.error "Config file not found: #{ex.}" raise ConfigurationError, "Config file not found: #{ex.}" rescue StandardError => ex SmartAgent.logger.error "Error loading configuration: #{ex.}" raise ConfigurationError, "Error loading configuration: #{ex.}" ensure SmartAgent.logger.info "Configuration loaded successfully" end end |
#load_mcp_server ⇒ Object
53 54 55 56 57 |
# File 'lib/smart_agent/engine.rb', line 53 def load_mcp_server Dir.glob(File.join(@config["mcp_path"], "*.rb")).each do |file| require(file) end end |
#load_tools ⇒ Object
47 48 49 50 51 |
# File 'lib/smart_agent/engine.rb', line 47 def load_tools Dir.glob(File.join(@config["tools_path"], "*.rb")).each do |file| require(file) end end |