Class: DeepagentsRails::Service
- Inherits:
-
Object
- Object
- DeepagentsRails::Service
- Defined in:
- lib/deepagents_rails/service.rb
Overview
Service class for interacting with DeepAgents in a Rails application
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#available_agents ⇒ Array<String>
Get a list of available agents.
-
#available_tools ⇒ Array<DeepAgents::Tool>
Get a list of available tools.
-
#initialize(agent_name = nil, options = {}) ⇒ Service
constructor
Initialize a new DeepAgents service.
-
#run(input, context = {}) ⇒ Hash
Run the agent with the given input.
Constructor Details
#initialize(agent_name = nil, options = {}) ⇒ Service
Initialize a new DeepAgents service
11 12 13 14 15 16 17 18 |
# File 'lib/deepagents_rails/service.rb', line 11 def initialize(agent_name = nil, = {}) @config = DeepagentsRails::Engine.config.deepagents @agent_name = agent_name || :default @options = # Load the agent if specified load_agent if @agent_name end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
6 7 8 |
# File 'lib/deepagents_rails/service.rb', line 6 def agent @agent end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
6 7 8 |
# File 'lib/deepagents_rails/service.rb', line 6 def config @config end |
Instance Method Details
#available_agents ⇒ Array<String>
Get a list of available agents
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/deepagents_rails/service.rb', line 58 def available_agents agents = [] # Load agents from the Rails app Dir[Rails.root.join('app/deepagents/agents/**/*_agent.rb')].each do |file| # Extract the agent name from the file path agent_name = File.basename(file, '.rb').gsub('_agent', '') agents << agent_name end agents end |
#available_tools ⇒ Array<DeepAgents::Tool>
Get a list of available tools
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/deepagents_rails/service.rb', line 33 def available_tools tools = [] # Load tools from the Rails app Dir[Rails.root.join('app/deepagents/tools/**/*_tool.rb')].each do |file| require file # Extract the tool class name from the file path tool_name = File.basename(file, '.rb').gsub('_tool', '') tool_class_name = tool_name.camelize # Try to load the tool class begin tool_class = "Deepagents::Tools::#{tool_class_name}Tool".constantize tools << tool_class.build if tool_class.respond_to?(:build) rescue NameError => e Rails.logger.warn("Could not load tool class for #{tool_name}: #{e.}") end end tools end |
#run(input, context = {}) ⇒ Hash
Run the agent with the given input
24 25 26 27 28 29 |
# File 'lib/deepagents_rails/service.rb', line 24 def run(input, context = {}) ensure_agent_loaded # Run the agent @agent.run(input, context) end |