discourse/plugins/discourse-ai/lib/automation/ai_tool_action.rb
Sam e3fae646d4
DEV: AI persona to agent migration (#38319)
Co-authored-by: Keegan George <kgeorge13@gmail.com>
2026-03-10 15:59:45 +11:00

27 lines
823 B
Ruby
Vendored

# frozen_string_literal: true
module DiscourseAi
module Automation
module AiToolAction
def self.handle(post:, tool_id:, llm_model_id: nil, automation: nil)
tool = ::AiTool.includes(:secret_bindings).find_by(id: tool_id, enabled: true)
return if !tool
llm =
LlmModel.find_by(id: llm_model_id)&.then { |m| DiscourseAi::Completions::Llm.proxy(m) }
context =
DiscourseAi::Agents::BotContext.new(
post: post,
feature_name: "ai_tool_action",
feature_context: {
automation_id: automation&.id,
automation_name: automation&.name,
},
)
runner = tool.runner({}, llm: llm, bot_user: Discourse.system_user, context: context)
runner.invoke
end
end
end
end