Class: RubyLLM::Agents::AgentsController Private
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- RubyLLM::Agents::AgentsController
- Includes:
- Filterable, Paginatable
- Defined in:
- app/controllers/ruby_llm/agents/agents_controller.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Controller for viewing agent details and per-agent analytics
Provides an overview of all registered agents and detailed views for individual agents including configuration, execution history, and performance metrics.
Constant Summary collapse
- AGENT_SORTABLE_COLUMNS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Allowed sort columns for the agents list (in-memory sorting)
%w[name agent_type model execution_count total_cost success_rate last_executed].freeze
- DEFAULT_AGENT_SORT_COLUMN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"name"- DEFAULT_AGENT_SORT_DIRECTION =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"asc"
Constants included from Filterable
Instance Method Summary collapse
-
#index ⇒ void
private
Lists all registered agents with their details.
-
#reset_overrides ⇒ void
private
Removes all dashboard overrides for an agent.
-
#show ⇒ void
private
Shows detailed view for a specific agent.
-
#update ⇒ void
private
Saves dashboard overrides for an agent’s overridable settings.
Instance Method Details
#index ⇒ void
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.
This method returns an undefined value.
Lists all registered agents with their details
Uses AgentRegistry to discover agents from both file system and execution history, ensuring deleted agents with history are still visible. Separates agents and workflows for tabbed display. Deleted agents are shown in a separate tab.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/controllers/ruby_llm/agents/agents_controller.rb', line 32 def index all_items = AgentRegistry.all_with_details # Filter to only agents (not workflows) all_agents = all_items.reject { |a| a[:is_workflow] } # Separate active and deleted agents @agents = all_agents.select { |a| a[:active] } @deleted_agents = all_agents.reject { |a| a[:active] } # Parse and apply sorting to both lists @sort_params = parse_agent_sort_params @agents = sort_agents(@agents) @deleted_agents = sort_agents(@deleted_agents) # Group active agents by type for sub-tabs @agents_by_type = { agent: @agents.select { |a| a[:agent_type] == "agent" }, embedder: @agents.select { |a| a[:agent_type] == "embedder" }, speaker: @agents.select { |a| a[:agent_type] == "speaker" }, transcriber: @agents.select { |a| a[:agent_type] == "transcriber" }, image_generator: @agents.select { |a| a[:agent_type] == "image_generator" }, router: @agents.select { |a| a[:agent_type] == "router" } } @agent_count = @agents.size @deleted_count = @deleted_agents.size rescue => e Rails.logger.error("[RubyLLM::Agents] Error loading agents: #{e.}") @agents = [] @deleted_agents = [] @agents_by_type = {agent: [], embedder: [], speaker: [], transcriber: [], image_generator: [], router: []} @agent_count = 0 @deleted_count = 0 @sort_params = {column: DEFAULT_AGENT_SORT_COLUMN, direction: DEFAULT_AGENT_SORT_DIRECTION} flash.now[:alert] = "Error loading agents list" end |
#reset_overrides ⇒ void
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.
This method returns an undefined value.
Removes all dashboard overrides for an agent
146 147 148 149 150 151 |
# File 'app/controllers/ruby_llm/agents/agents_controller.rb', line 146 def reset_overrides @agent_type = CGI.unescape(params[:id]) override = AgentOverride.find_by(agent_type: @agent_type) override&.destroy redirect_to agent_path(@agent_type), notice: "Overrides cleared" end |
#show ⇒ void
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.
This method returns an undefined value.
Shows detailed view for a specific agent
Loads agent configuration (if class exists), statistics, filtered executions, and chart data for visualization. Works for both active agents and deleted agents with history.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'app/controllers/ruby_llm/agents/agents_controller.rb', line 77 def show @agent_type = CGI.unescape(params[:id]) @agent_class = AgentRegistry.find(@agent_type) @agent_active = @agent_class.present? load_agent_stats load_filtered_executions load_chart_data if @agent_class load_agent_config # Load circuit breaker status for agents that support reliability load_circuit_breaker_status if @agent_type_kind.in?(%w[agent router]) end rescue => e Rails.logger.error("[RubyLLM::Agents] Error loading agent #{@agent_type}: #{e.}") redirect_to ruby_llm_agents.agents_path, alert: "Error loading agent details" end |
#update ⇒ void
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.
This method returns an undefined value.
Saves dashboard overrides for an agent’s overridable settings
Only persists values for fields the agent has declared as ‘overridable: true` in its DSL. Ignores all other fields.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'app/controllers/ruby_llm/agents/agents_controller.rb', line 103 def update @agent_type = CGI.unescape(params[:id]) @agent_class = AgentRegistry.find(@agent_type) unless @agent_class redirect_to ruby_llm_agents.agents_path, alert: "Agent not found" return end allowed = @agent_class.overridable_fields.map(&:to_s) if allowed.empty? redirect_to agent_path(@agent_type), alert: "This agent has no overridable fields" return end # Build settings hash from permitted params, only for overridable fields settings = {} allowed.each do |field| next unless params.dig(:override, field).present? raw = params[:override][field] settings[field] = coerce_override_value(field, raw) end override = AgentOverride.find_or_initialize_by(agent_type: @agent_type) if settings.empty? # No overrides left — delete the record override.destroy if override.persisted? redirect_to agent_path(@agent_type), notice: "Overrides cleared" else override.settings = settings if override.save redirect_to agent_path(@agent_type), notice: "Overrides saved" else redirect_to agent_path(@agent_type), alert: "Failed to save overrides" end end end |