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:
-
✅ ModelMetadataInterceptorcorrectly sets the model metadata in the context -
❌ AgentComponent.attach()callsprompt_registry.get()without passingmodel_metadata -
❌ The prompt registry falls back to the default model for the feature setting -
❌ The flow executes with the wrong model (e.g.,claude_sonnet_4_20250514instead ofgpt_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:
-
AgentComponentprompt = self.prompt_registry.get( self.prompt_id, self.prompt_version, tools=tools, tool_choice=tool_choice ) # ❌ No model_metadata parameter -
OneOffComponentprompt = self.prompt_registry.get( self.prompt_id, self.prompt_version, tools=tools, tool_choice=tool_choice ) # ❌ No model_metadata parameter -
HumanInputComponentprompt = 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_contextfix_pipeline_create_planfix_pipeline_executioncommit_changesfix_pipeline_push_changes
|
resolve_sast_vulnerability |
4 AgentComponent 1 OneOffComponent |
resolve_sast_vulnerability_contextresolve_sast_vulnerability_executionresolve_sast_check_false_positiveresolve_sast_evaluate_mr_readinessresolve_sast_vulnerability_commit_and_push
|
sast_fp_detection |
3 AgentComponent 3 OneOffComponent |
validate_sast_vulnerability_agent_promptsast_vulnerability_source_file_agent_promptsast_vulnerability_lines_agent_promptsast_vulnerability_report_agent_promptsast_fp_detection_agent_promptsast_post_results_to_gitlab_agent_prompt
|
code_review |
2 AgentComponent |
code_review_prescanreview_merge_request
|
Expected Behavior
When a model is specified in the request headers:
- The flow should use that specific model
- If a model-specific prompt exists (e.g.,
fix_pipeline_execution/gpt_5/1.0.0.yml), it should be loaded - The model provider should be set correctly (e.g.,
openaifor GPT models, notanthropic)
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.pyduo_workflow_service/agent_platform/v1/components/one_off/component.pyduo_workflow_service/agent_platform/experimental/components/agent/component.pyduo_workflow_service/agent_platform/experimental/components/one_off/component.pyduo_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_ciissue_to_merge_requestsoftware_developmentchat
❌ Flows That Don't Work
All Agent Platform V1 flows using the component architecture.