From 66a15bb1677111bdee8084eb042d36dbf54b6220 Mon Sep 17 00:00:00 2001 From: Luke Duncalfe Date: Wed, 10 Sep 2025 12:24:33 +1200 Subject: [PATCH] Set agent test titles in Agent Sessions `workflow_definition` usually matches the hard-coded Workflow in Workflow Service. For `flow_config` flows (ones that dynamically sent to Workflow Service from Rails) the `workflow_definition` is ignored, as there is no hard-coded Workflow. However, this value does appear in the Agent Sessions page. This change updates this value to be more descriptive of an agent test so that is appears in the Agent Sessions section with a descriptive title. https://gitlab.com/gitlab-org/gitlab/-/issues/568911 --- .../ai/catalog/agents/execute_service.rb | 6 ++++- ee/lib/ai/catalog/execute_workflow_service.rb | 14 +++++------ .../ai/catalog/agents/execute_service_spec.rb | 10 ++++++++ .../catalog/execute_workflow_service_spec.rb | 23 +++++++++++++++---- locale/gitlab.pot | 3 +++ 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/ee/app/services/ai/catalog/agents/execute_service.rb b/ee/app/services/ai/catalog/agents/execute_service.rb index 044ed30d3eb5f8..a5ac29b97cf424 100644 --- a/ee/app/services/ai/catalog/agents/execute_service.rb +++ b/ee/app/services/ai/catalog/agents/execute_service.rb @@ -67,7 +67,11 @@ def execute_workflow_service(flow_config) params = { json_config: flow_config, container: agent.project, - goal: agent_goal + goal: agent_goal, + flow_name: format( + s_('AICatalog|Agent test: %{agent_name} (Agent ID %{agent_id})'), + agent_name: agent.name, agent_id: agent.id + ) } ::Ai::Catalog::ExecuteWorkflowService.new(current_user, params).execute diff --git a/ee/lib/ai/catalog/execute_workflow_service.rb b/ee/lib/ai/catalog/execute_workflow_service.rb index aad34e64e8a704..1aebd320c47d23 100644 --- a/ee/lib/ai/catalog/execute_workflow_service.rb +++ b/ee/lib/ai/catalog/execute_workflow_service.rb @@ -7,12 +7,14 @@ class ExecuteWorkflowService FLOW_CONFIG_VERSION = 'experimental' WORKFLOW_ENVIRONMENT = 'web' + DEFAULT_FLOW_NAME = 'ai_catalog_flow' def initialize(current_user, params) @current_user = current_user @json_config = params[:json_config] @container = params[:container] @goal = params[:goal] + @flow_name = params[:flow_name] || DEFAULT_FLOW_NAME end def execute @@ -37,7 +39,7 @@ def execute private - attr_reader :current_user, :json_config, :container, :goal + attr_reader :current_user, :json_config, :container, :goal, :flow_name def error(message, payload: {}) ServiceResponse.error(message: Array(message), payload: payload) @@ -55,7 +57,7 @@ def validate def create_workflow workflow_params = { goal: goal, - workflow_definition: determine_workflow_definition, + workflow_definition: flow_name, environment: WORKFLOW_ENVIRONMENT } @@ -87,7 +89,7 @@ def build_start_workflow_params(workflow) { goal: goal, - workflow_definition: determine_workflow_definition, + workflow_definition: flow_name, flow_config: json_config, flow_config_schema_version: FLOW_CONFIG_VERSION, workflow_id: workflow.id, @@ -103,14 +105,10 @@ def token_generation_service ::Ai::DuoWorkflows::TokenGenerationService.new( current_user: current_user, organization: container.organization, - workflow_definition: determine_workflow_definition + workflow_definition: flow_name ) end - def determine_workflow_definition - 'software_development' - end - def allowed? Ability.allowed?(current_user, :admin_ai_catalog_item, container) end diff --git a/ee/spec/services/ai/catalog/agents/execute_service_spec.rb b/ee/spec/services/ai/catalog/agents/execute_service_spec.rb index 3084c5319c3102..c513c065a297d0 100644 --- a/ee/spec/services/ai/catalog/agents/execute_service_spec.rb +++ b/ee/spec/services/ai/catalog/agents/execute_service_spec.rb @@ -153,6 +153,16 @@ expect(result[:workload_id]).to eq(Ci::Workloads::Workload.last.id) end + it 'creates a Ai::DuoWorkflows::Workflow correctly' do + expect { execute }.to change { Ai::DuoWorkflows::Workflow.count }.by(1) + + workflow_session = Ai::DuoWorkflows::Workflow.last + + expect(workflow_session.workflow_definition).to eq( + "Agent test: #{agent.name} (Agent ID #{agent.id})" + ) + end + it 'triggers trigger_ai_catalog_item', :clean_gitlab_redis_shared_state do expect { execute } .to trigger_internal_events('trigger_ai_catalog_item') diff --git a/ee/spec/services/ai/catalog/execute_workflow_service_spec.rb b/ee/spec/services/ai/catalog/execute_workflow_service_spec.rb index 64b8a85d03a425..cdce950c033553 100644 --- a/ee/spec/services/ai/catalog/execute_workflow_service_spec.rb +++ b/ee/spec/services/ai/catalog/execute_workflow_service_spec.rb @@ -154,15 +154,30 @@ context 'when workflow creation succeeds' do it_behaves_like 'starts workflow execution' - it 'creates the Ai::DuoWorkflows::Workflow' do + it 'creates a Ai::DuoWorkflows::Workflow correctly' do expect do service.execute end.to change { Ai::DuoWorkflows::Workflow.count }.by(1) - created_workflow = Ai::DuoWorkflows::Workflow.last + workflow_session = Ai::DuoWorkflows::Workflow.last - expect(created_workflow.goal).to eq(goal) - expect(created_workflow.environment).to eq("web") + expect(workflow_session).to have_attributes( + goal: goal, + environment: 'web', + workflow_definition: described_class::DEFAULT_FLOW_NAME + ) + end + + context 'when a flow_name is passed' do + let(:params) { super().merge(flow_name: 'My flow name') } + + it 'creates the Ai::DuoWorkflows::Workflow with the flow_name as the workflow_definition' do + service.execute + + workflow_session = Ai::DuoWorkflows::Workflow.last + + expect(workflow_session.workflow_definition).to eq('My flow name') + end end context 'when oauth token creation fails' do diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 3f4ac2c8c90502..68e31542a00e1d 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -2473,6 +2473,9 @@ msgstr "" msgid "AICatalog|Agent not found." msgstr "" +msgid "AICatalog|Agent test: %{agent_name} (Agent ID %{agent_id})" +msgstr "" + msgid "AICatalog|Agent updated successfully." msgstr "" -- GitLab