Skip to content

Agent Platform V1 flows ignore model_metadata from request headers, so model switching does not work for those flows

Summary

All Agent Platform V1 flows (fix_pipeline, resolve_sast_vulnerability, sast_fp_detection, code_review) do not respect the model_metadata passed in request headers (e.g., x-gitlab-agent-platform-model-metadata). When a user passes a specific model like gpt_5 via the header, these flows ignore it and use the default model from their feature setting instead.

Current Behavior

When a request is made to an Agent Platform V1 flow with model_identifier: "gpt_5" in the x-gitlab-agent-platform-model-metadata header:

  1. ModelMetadataInterceptor correctly sets the model metadata in the context
  2. AgentComponent.attach() calls prompt_registry.get() without passing model_metadata
  3. The prompt registry falls back to the default model for the feature setting
  4. The flow executes with the wrong model (e.g., claude_sonnet_4_20250514 instead of gpt_5)

Root Cause

The issue is in the Agent Platform V1 component architecture:

Affected Components

All three component types call prompt_registry.get() without model_metadata:

  1. AgentComponent

    prompt = self.prompt_registry.get(
        self.prompt_id, self.prompt_version, tools=tools, tool_choice=tool_choice
    )  # ❌ No model_metadata parameter
  2. OneOffComponent

    prompt = self.prompt_registry.get(
        self.prompt_id, self.prompt_version, tools=tools, tool_choice=tool_choice
    )  # ❌ No model_metadata parameter
  3. HumanInputComponent

    prompt = self.prompt_registry.get(self.prompt_id, self.prompt_version)
    # ❌ No model_metadata parameter

Why This Matters

The BasePromptRegistry.get() method does NOT automatically retrieve from context:

# ai_gateway/prompts/registry.py:308-316
def get(
    self,
    prompt_id: str,
    prompt_version: str | None,
    model_metadata: Optional[TypeModelMetadata] = None,  # If None, uses default
    ...
) -> Prompt:

Affected Flows

All Agent Platform V1 flows are affected:

Flow Components Affected Prompts Affected
fix_pipeline 4 AgentComponent
1 OneOffComponent
fix_pipeline_context
fix_pipeline_create_plan
fix_pipeline_execution
commit_changes
fix_pipeline_push_changes
resolve_sast_vulnerability 4 AgentComponent
1 OneOffComponent
resolve_sast_vulnerability_context
resolve_sast_vulnerability_execution
resolve_sast_check_false_positive
resolve_sast_evaluate_mr_readiness
resolve_sast_vulnerability_commit_and_push
sast_fp_detection 3 AgentComponent
3 OneOffComponent
validate_sast_vulnerability_agent_prompt
sast_vulnerability_source_file_agent_prompt
sast_vulnerability_lines_agent_prompt
sast_vulnerability_report_agent_prompt
sast_fp_detection_agent_prompt
sast_post_results_to_gitlab_agent_prompt
code_review 2 AgentComponent code_review_prescan
review_merge_request

Expected Behavior

When a model is specified in the request headers:

  1. The flow should use that specific model
  2. If a model-specific prompt exists (e.g., fix_pipeline_execution/gpt_5/1.0.0.yml), it should be loaded
  3. The model provider should be set correctly (e.g., openai for GPT models, not anthropic)

Proposed Solution

Option 1: Retrieve from Context

Update all three component types to retrieve model_metadata from context:

from ai_gateway.model_metadata import current_model_metadata_context

def attach(self, graph: StateGraph, router: RouterProtocol) -> None:
    tools = self.toolset.bindable + [AgentFinalOutput]
    tool_choice = "any"

    prompt = self.prompt_registry.get(
        self.prompt_id, 
        self.prompt_version, 
        model_metadata=current_model_metadata_context.get(),  # ✅ Add this
        tools=tools, 
        tool_choice=tool_choice
    )
    # ... rest of method

Files to update:

  • duo_workflow_service/agent_platform/v1/components/agent/component.py
  • duo_workflow_service/agent_platform/v1/components/one_off/component.py
  • duo_workflow_service/agent_platform/experimental/components/agent/component.py
  • duo_workflow_service/agent_platform/experimental/components/one_off/component.py
  • duo_workflow_service/agent_platform/experimental/components/human_input/component.py

Flows That Work Correctly

These older workflows use get_on_behalf() and respect model metadata:

  • convert_to_gitlab_ci
  • issue_to_merge_request
  • software_development
  • chat

Flows That Don't Work

All Agent Platform V1 flows using the component architecture.