Class: RailsAgents::ToolBridgeController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails_agents/tool_bridge_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/rails_agents/tool_bridge_controller.rb', line 12

def create
  return render json: { error: "Unauthorized" }, status: :unauthorized unless authorized_runtime?

  klass = load_agent_class(params[:agent])
  tool = klass&.tool_definitions&.fetch(params[:tool].to_sym, nil)
  return render json: { error: "Tool not found" }, status: :not_found unless tool

  arguments = request.request_parameters.presence || {}
  result = tool.call(**arguments.deep_symbolize_keys)
  render json: { ok: true, result: result }
rescue ArgumentError => e
  render json: { error: e.message }, status: :unprocessable_entity
rescue StandardError => e
  Rails.logger.error("[RailsAgents::ToolBridge] #{e.class}: #{e.message}")
  render json: { error: "Tool execution failed" }, status: :internal_server_error
end