Add DWS ValidateFlowConfig gRPC integration for custom flows
What does this MR do and why?
Calls the DWS ValidateFlowConfig gRPC endpoint when users create or update custom flows in AI Catalog. This surfaces semantic validation errors (missing inputs, unknown tool params, prompt template issues) early, before the flow is saved, instead of at runtime.
Changes:
- Adds validate_flow_config method to the DWS gRPC client with a 10s timeout
- Adds a model-level gate (dws_flow_config_validated) on Ai::Catalog::ItemVersion to ensure any code path saving a custom flow must validate with DWS first
- Calls DWS validation in both flow create and update services via a shared DwsFlowConfigValidator concern
- Updates the vendor gem to include the new ValidateFlowConfig proto stubs
- If DWS is unavailable, the mutation fails with a user-friendly error (flows are never saved unvalidated)
References
Issue: #597224 (closed)
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
1. Checkout this branch and start GDK 2. Create flow with invalid YAML
Create a custom flow using the below definition
# Schema version
version: "v1"
# Environment where the flow runs (ambient = GitLab's managed environment)
environment: ambient
# Components define the steps in your flow
# Each component can be an Agent, DeterministicStep, or other component types
components:
- name: "my_agent"
type: AgentComponent # Options: AgentComponent, DeterministicStepComponent
prompt_id: "my_prompt" # References a prompt defined below
inputs:
- "context:goal" # Input from user or previous component
toolset: [] # Add tool names here: ["get_issue", "create_issue_note"]
# Optional: UI logging
ui_log_events:
- "on_agent_final_answer"
- "on_tool_execution_success"
# Define your prompts here
# Each prompt configures an AI agent's behavior
prompts:
- prompt_id: "my_prompt" # Must match the prompt_id referenced above
name: "My Agent Prompt"
# System and user prompts define the agent's behavior
prompt_template:
system: |
You are {{GitLab}} Duo Chat, an agentic AI assistant.
Your role is to help users with their GitLab tasks.
Be concise, accurate, and actionable in your responses.
# Add specific instructions for your use case here
# Available variables depend on your inputs:
# {{goal}} - The user's request
# {{context}} - Additional context from previous steps
user: |
{{goal}}
placeholder: history # Maintains conversation context
unit_primitives: []
params:
timeout: 180 # Seconds before timeout
# Routers define the flow between components
# Use "end" as the final destination
routers:
- from: "my_agent"
to: "end"
# Example: Multi-step flow
# - from: "fetch_data"
# to: "process_data"
# - from: "process_data"
# to: "my_agent"
# - from: "my_agent"
# to: "end"
# Define the entry point for your flow
flow:
entry_point: "my_agent"
Previously this flow would be created successfully. Now you will see DWS validation errors surfaced in the UI.
3. Create flow with valid YAML
Create a custom flow using the below definition
# Schema version
version: "v1"
# Environment where the flow runs (ambient = GitLab's managed environment)
environment: ambient
# Components define the steps in your flow
# Each component can be an Agent, DeterministicStep, or other component types
components:
- name: "my_agent"
type: AgentComponent # Options: AgentComponent, DeterministicStepComponent
prompt_id: "my_prompt" # References a prompt defined below
inputs:
- "context:goal" # Input from user or previous component
toolset: [] # Add tool names here: ["get_issue", "create_issue_note"]
# Optional: UI logging
ui_log_events:
- "on_agent_final_answer"
- "on_tool_execution_success"
# Define your prompts here
# Each prompt configures an AI agent's behavior
prompts:
- prompt_id: "my_prompt" # Must match the prompt_id referenced above
name: "My Agent Prompt"
# System and user prompts define the agent's behavior
prompt_template:
system: |
You are GitLab Duo Chat, an agentic AI assistant.
Your role is to help users with their GitLab tasks.
Be concise, accurate, and actionable in your responses.
# Add specific instructions for your use case here
# Available variables depend on your inputs:
# {{goal}} - The user's request
# {{context}} - Additional context from previous steps
user: |
{{goal}}
placeholder: history # Maintains conversation context
unit_primitives: []
params:
timeout: 180 # Seconds before timeout
# Routers define the flow between components
# Use "end" as the final destination
routers:
- from: "my_agent"
to: "end"
# Example: Multi-step flow
# - from: "fetch_data"
# to: "process_data"
# - from: "process_data"
# to: "my_agent"
# - from: "my_agent"
# to: "end"
# Define the entry point for your flow
flow:
entry_point: "my_agent"
It will be saved successfully.
4. Verify DWS unavailable behavior
- Stop the Duo Workflow Service:
gdk stop duo-workflow-service - Try creating a custom flow. You will see the error:
5. Verify 10 second timeout
Add a sleep in the DWS server at gitlab-ai-gateway/duo_workflow_service/server.py line 619:
log.info("Validating flow config")
await asyncio.sleep(15) # TEMP: add this line to test timeoutStart the DWS server and try creating a custom flow. Since we have a 10 second timeout, after ~10 seconds you will see the error:
Remove the sleep after testing.
6. Verify flow update: Repeat steps 2-5 above but by editing an existing custom flow instead of creating a new one. The same validation behavior should apply on update.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #597224 (closed)
