A platform for community discussion. Free, open, simple.
FEATURE: Resolve topics by title or id in workflow AI authoring
Régis Hanol1d0c6dbd4b90
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_resolve_entity.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_resolve_entity.rbindex b55ebd26a97..7ea7e9817b4 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_resolve_entity.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai/tools/workflow_resolve_entity.rb@@ -4,7 +4,7 @@ module DiscourseWorkflowsmodule Aimodule Toolsclass WorkflowResolveEntity < Base- SUPPORTED_KINDS = %w[category tag tag_group user group badge data_table].freeze+ SUPPORTED_KINDS = %w[category tag tag_group user group badge data_table topic].freezeMAX_RESULTS = 10def self.signature@@ -21,7 +21,7 @@ module DiscourseWorkflows},{name: "query",- description: "Name, slug, username, or partial text to search for",+ description: "Name, slug, username, topic id, or partial text to search for",type: "string",required: true,},@@ -104,6 +104,22 @@ module DiscourseWorkflows.map { |id, name| { id: id, name: name } }end+ def resolve_topic(query)+ scope = Topic.listable_topics+ scope =+ if query.match?(/\A\d+\z/)+ scope.where(id: query.to_i)+ else+ scope.where("title ILIKE ?", "%#{Topic.sanitize_sql_like(query)}%")+ end++ scope+ .order(bumped_at: :desc)+ .limit(MAX_RESULTS)+ .pluck(:id, :title, :slug)+ .map { |id, title, slug| { id: id, title: title, slug: slug } }+ end+def resolve_data_table(query)DiscourseWorkflows::DataTable.where("name ILIKE ?", "%#{DiscourseWorkflows::DataTable.sanitize_sql_like(query)}%")diff --git a/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb b/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rbindex dd5ef8ea14b..991a88b6b82 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/ai_workflow_author.rb@@ -52,7 +52,7 @@ module DiscourseWorkflows- Use the compact workflow authoring context supplied with the request before proposing changes, and call workflow_graph_context/workflow_node_catalog for details when needed.- Do not ask admins for exact IDs, slugs, or names when an available tool can look them up; use discovery and resolver tools first.- Use categories, tags, search, read, and time tools for current forum discovery when they help draft the workflow safely; do not use forum search/read to discover workflow node behavior or schemas because workflow_node_catalog and workflow_validate_patch return schema details.- - Use workflow_resolve_entity when the user names a category, tag, tag group, group, user, badge, or data table and you need its exact workflow parameter value.+ - Use workflow_resolve_entity when the user names a category, tag, tag group, group, user, badge, data table, or topic and you need its exact workflow parameter value. Topic ids go in the topic_ids filter, which only the triggers that list it in workflow_node_catalog support.- Use workflow_ai_agent_catalog before adding action:ai_agent nodes. Reuse a suitable enabled AI agent by setting agent_id to its numeric id. Only propose a new agent when the workflow genuinely needs AI judgment/generation and no suitable enabled agent exists.- New AI agents must be prompt-only by default: name, description, and system_prompt only. Do not add tools, RAG, MCP servers, bot users, mention permissions, default LLM overrides, or broad group access for generated agents.- Keep generated AI agent system prompts focused on the workflow task. A simple helpful prompt is acceptable when the task is broad, but prefer concise task-specific instructions when the workflow needs a clear output.diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_resolve_entity_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_resolve_entity_spec.rbindex 3701749ab3c..35b37e3ca98 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_resolve_entity_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/ai/tools/workflow_resolve_entity_spec.rb@@ -21,6 +21,30 @@ RSpec.describe DiscourseWorkflows::Ai::Tools::WorkflowResolveEntity do)end+ it "resolves topics by title or id", :aggregate_failures do+ topic = Fabricate(:topic, title: "Can you solve a Rubik's cube?")+ Fabricate(:topic, title: "Unrelated topic")+ Fabricate(:private_message_topic, title: "Rubik's cube private chat")+ context = DiscourseAi::Agents::BotContext.new(messages: [], user: admin)+ resolve = ->(query) do+ described_class.new(+ { kind: "topic", query: },+ bot_user: Discourse.system_user,+ llm: nil,+ context:,+ ).invoke+ end++ expected = {+ status: "success",+ kind: "topic",+ matches: [{ id: topic.id, title: topic.title, slug: topic.slug }],+ }++ expect(resolve.("rubik")).to eq(expected)+ expect(resolve.(topic.id.to_s)).to eq(expected)+ end+it "resolves tag groups by name" dotag_group = Fabricate(:tag_group, name: "Customer lifecycle")Fabricate(:tag_group, name: "Unrelated")