Skip to content

Hook up the auto mode router#4302

Merged
lramos15 merged 5 commits intomainfrom
lramos15/auto-router
Mar 10, 2026
Merged

Hook up the auto mode router#4302
lramos15 merged 5 commits intomainfrom
lramos15/auto-router

Conversation

@lramos15
Copy link
Member

@lramos15 lramos15 commented Mar 9, 2026

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 RouterDecisionFetcher to use ICAPIClientService.makeRequest with the new RequestType.ModelRouter, removing manual retry logic and URL-based auth handling (now delegated to CAPI client).
  • Unified AutomodeService.resolveAutoModeEndpoint into a single method (eliminating the split _resolveWithRouterModel/_resolveWithoutRouterModel paths) and simplified the cache from an array of endpoints to a single endpoint.
  • Replaced the AutoModeRouterUrl string config key with a boolean UseAutoModeRouting flag, and bumped @vscode/copilot-api from 0.2.15 to 0.2.16 to get the RequestType.ModelRouter enum.

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.ts has been deleted but RouterDecisionFetcher.getRouterDecision still contains non-trivial logic: response parsing via response.text() + JSON.parse(), response validation via routerDecisionResponseValidator, and telemetry reporting. None of this is directly tested anymore. The integration tests in automodeService.spec.ts only verify routing behavior at the AutomodeService level and mock the CAPI client responses, bypassing RouterDecisionFetcher's parsing and validation logic. Consider adding unit tests for getRouterDecision to 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;
	}

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 3 comments.

@lramos15 lramos15 marked this pull request as ready for review March 9, 2026 19:56
@vs-code-engineering vs-code-engineering bot added this to the 1.112.0 milestone Mar 9, 2026
@lramos15 lramos15 added this pull request to the merge queue Mar 9, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Mar 10, 2026
@lramos15 lramos15 added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit bccedc5 Mar 10, 2026
19 checks passed
@lramos15 lramos15 deleted the lramos15/auto-router branch March 10, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants