Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hooks up the auto mode router by refactoring RouterDecisionFetcher to use the CAPI client service (ICAPIClientService) instead of direct HTTP fetch (IFetcherService), and unifies the model selection logic in AutomodeService into a single code path. The router performs intent-based task detection to select the best model, with fallback to capacity-based routing on failure.
Changes:
- Refactored
RouterDecisionFetcherto useICAPIClientService.makeRequestwith the newRequestType.ModelRouter, removing manual retry logic and URL-based auth handling (now delegated to CAPI client). - Unified
AutomodeService.resolveAutoModeEndpointinto a single method (eliminating the split_resolveWithRouterModel/_resolveWithoutRouterModelpaths) and simplified the cache from an array of endpoints to a single endpoint. - Replaced the
AutoModeRouterUrlstring config key with a booleanUseAutoModeRoutingflag, and bumped@vscode/copilot-apifrom0.2.15to0.2.16to get theRequestType.ModelRouterenum.
Reviewed changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/platform/endpoint/node/routerDecisionFetcher.ts |
Rewrote to use CAPI client, removed retry/URL logic, changed from Disposable to plain class, exported RouterDecisionResponse interface |
src/platform/endpoint/node/automodeService.ts |
Merged two resolution paths into one, simplified cache structure (array → single endpoint), added _isRouterEnabled helper, removed IFetcherService dependency |
src/platform/configuration/common/configurationService.ts |
Replaced AutoModeRouterUrl (string) config key with UseAutoModeRouting (boolean) |
src/platform/endpoint/node/test/automodeService.spec.ts |
Updated tests for new API: CAPI client mocks, new router fallback and vision tests |
src/platform/endpoint/node/test/routerDecisionFetcher.spec.ts |
Deleted — unit tests for the old RouterDecisionFetcher implementation |
package.json / package-lock.json |
Bumped @vscode/copilot-api to ^0.2.16 |
Comments suppressed due to low confidence (1)
src/platform/endpoint/node/routerDecisionFetcher.ts:91
- The entire
routerDecisionFetcher.spec.tshas been deleted butRouterDecisionFetcher.getRouterDecisionstill contains non-trivial logic: response parsing viaresponse.text()+JSON.parse(), response validation viarouterDecisionResponseValidator, and telemetry reporting. None of this is directly tested anymore. The integration tests inautomodeService.spec.tsonly verify routing behavior at theAutomodeServicelevel and mock the CAPI client responses, bypassingRouterDecisionFetcher's parsing and validation logic. Consider adding unit tests forgetRouterDecisionto cover response validation errors, malformed responses, and HTTP error scenarios.
async getRouterDecision(query: string, autoModeToken: string, availableModels: string[]): Promise<RouterDecisionResponse> {
const response = await this._capiClientService.makeRequest<Response>({
method: 'POST',
headers: {
'Authorization': `Bearer ${(await this._authService.getCopilotToken()).token}`,
'Copilot-Session-Token': autoModeToken,
},
body: JSON.stringify({ prompt: query, available_models: availableModels })
}, { type: RequestType.ModelRouter });
const text = await response.text();
const { content: result, error: validationError } = routerDecisionResponseValidator.validate(JSON.parse(text));
if (validationError) {
throw new Error(`Invalid router decision response: ${validationError.message}`);
}
this._logService.trace(`[RouterDecisionFetcher] Prediction: ${result.predicted_label}, model: ${result.chosen_model} (confidence: ${(result.confidence * 100).toFixed(1)}%, scores: needs_reasoning=${(result.scores.needs_reasoning * 100).toFixed(1)}%, no_reasoning=${(result.scores.no_reasoning * 100).toFixed(1)}%) (latency_ms: ${result.latency_ms}, candidate models: ${result.candidate_models.join(', ')})`);
/* __GDPR__
"automode.routerDecision" : {
"owner": "lramos15",
"comment": "Reports the routing decision made by the auto mode router API",
"predictedLabel": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The predicted classification label (needs_reasoning or no_reasoning)" },
"chosenModel": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "comment": "The model selected by the router" },
"confidence": { "classification": "SystemMetaData", "purpose": "FeatureInsight", "isMeasurement": true, "comment": "The confidence score of the routing decision" },
"latencyMs": { "classification": "SystemMetaData", "purpose": "PerformanceAndHealth", "isMeasurement": true, "comment": "The latency of the router API call in milliseconds" }
}
*/
this._telemetryService.sendMSFTTelemetryEvent('automode.routerDecision',
{
predictedLabel: result.predicted_label,
chosenModel: result.chosen_model,
},
{
confidence: result.confidence,
latencyMs: result.latency_ms,
}
);
return result;
}
DonJayamanne
approved these changes
Mar 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hooks up the auto mode router and refactors a bunch of the code.
The router works by doing intent based task detection and falling back to the capacity based routing in the case of failures