Class: RubyLLM::Agents::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/ruby_llm/agents/rails/engine.rb

Overview

Rails Engine for RubyLLM::Agents

Provides a mountable dashboard for monitoring agent executions, with configurable authentication and automatic agent autoloading.

Examples:

Mounting the engine in routes.rb

Rails.application.routes.draw do
  mount RubyLLM::Agents::Engine => "/agents"
end

With authentication via parent controller

RubyLLM::Agents.configure do |config|
  config.dashboard_parent_controller = "AdminController"
end

See Also:

Class Method Summary collapse

Class Method Details

.namespace_for_path(path, config) ⇒ Module?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Determines the namespace constant for a given path

Parameters:

  • path (String)

    Relative path like “app/agents/embedders”

  • config (Configuration)

    Current configuration

Returns:

  • (Module, nil)

    Namespace module or nil for top-level



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'lib/ruby_llm/agents/rails/engine.rb', line 249

def self.namespace_for_path(path, config)
  parts = path.split("/")

  # Need at least app/{root_directory}
  return nil unless parts.length >= 2 && parts[0] == "app"
  return nil unless parts[1] == config.root_directory

  # app/agents -> no namespace (root level)
  return nil if parts.length == 2

  # app/agents/embedders -> Embedders namespace
  subdirectory = parts[2]
  namespace_name = if config.root_namespace.blank?
    subdirectory.camelize
  else
    "#{config.root_namespace}::#{subdirectory.camelize}"
  end

  # Create the namespace module if needed
  namespace_name.constantize
rescue NameError
  namespace_name.split("::").inject(Object) do |mod, name|
    mod.const_defined?(name, false) ? mod.const_get(name) : mod.const_set(name, Module.new)
  end
end