Resolve endpoint once per tool-calling round instead of per-method#5031
Open
abadawi591 wants to merge 4 commits intomicrosoft:mainfrom
Open
Resolve endpoint once per tool-calling round instead of per-method#5031abadawi591 wants to merge 4 commits intomicrosoft:mainfrom
abadawi591 wants to merge 4 commits intomicrosoft:mainfrom
Conversation
Add resolveEndpoint() to the base ToolCallingLoop and pass the resolved endpoint to buildPrompt, getAvailableTools, and fetch as a parameter. Each subclass's private getEndpoint() is replaced by an override of resolveEndpoint(), eliminating 4-5 redundant getChatEndpoint calls per round. Files changed: - toolCallingLoop.ts: add resolveEndpoint(), endpoint param on abstract methods - codebaseToolCalling.ts: override resolveEndpoint, remove getEndpoint - searchSubagentToolCallingLoop.ts: override resolveEndpoint, remove getEndpoint - executionSubagentToolCallingLoop.ts: override resolveEndpoint, remove getEndpoint - mcpToolCallingLoop.tsx: override resolveEndpoint, remove getEndpoint - defaultIntentRequestHandler.ts: accept endpoint param (uses invocation.endpoint)
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the tool-calling loop to resolve the chat endpoint once per tool-calling round (per runOne() iteration) and thread that resolved endpoint through prompt building, tool selection, and request execution to eliminate redundant endpoint resolution calls.
Changes:
- Added
resolveEndpoint()toToolCallingLoopand resolved the endpoint once at the start ofrunOne(). - Updated
ToolCallingLoopabstract method signatures to accept the resolvedIChatEndpoint, and updated concrete loops to match. - Migrated subagent/codebase/MCP loops from per-method endpoint resolution (
getEndpoint()) toresolveEndpoint()overrides.
Show a summary per file
| File | Description |
|---|---|
| src/extension/intents/node/toolCallingLoop.ts | Introduces resolveEndpoint() and threads a single resolved endpoint through runOne()/prompt/tools/fetch. |
| src/extension/prompt/node/codebaseToolCalling.ts | Switches to overriding resolveEndpoint() and reuses the resolved endpoint in build/tools/fetch. |
| src/extension/prompt/node/searchSubagentToolCallingLoop.ts | Switches to overriding resolveEndpoint() and accepts endpoint param for build/tools/fetch (but currently contains a broken import line). |
| src/extension/prompt/node/executionSubagentToolCallingLoop.ts | Switches to overriding resolveEndpoint() and accepts endpoint param for build/tools/fetch. |
| src/extension/mcp/vscode-node/mcpToolCallingLoop.tsx | Switches to overriding resolveEndpoint() and accepts endpoint param for build/fetch (but currently contains a broken import line). |
| src/extension/prompt/node/defaultIntentRequestHandler.ts | Updates DefaultToolCallingLoop method signatures to accept endpoint (currently unused). |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 4
Split the IChatEndpoint and IInstantiationService imports onto separate lines in searchSubagentToolCallingLoop.ts and mcpToolCallingLoop.tsx.
Add endpoint parameter to buildPrompt, getAvailableTools, and fetch overrides in UsageTestToolCallingLoop, TestToolCallingLoop, and AutopilotTestToolCallingLoop.
Return this.options.invocation.endpoint so runOne()'s token counting and model-family checks use the same endpoint as fetch/getAvailableTools.
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.
Resolve endpoint once per tool-calling round instead of per-method
Follow-up to https://github.com//pull/5027. That PR added promise coalescing in
automodeServiceto prevent duplicate telemetry. This PR eliminates the redundantgetChatEndpointcalls at the source.Problem
runOne()intoolCallingLoop.tscallsgetChatEndpoint(request)up to 5 times per round viagetAvailableTools,buildPrompt, token counting, andfetch. All calls return the same endpoint for the same round. This dates back to the initial repo (af813ee)resolveEndpoint()to the baseToolCallingLoop, called once at the top ofrunOne()buildPrompt,getAvailableTools, andfetchas a parametergetEndpoint()becomes an override ofresolveEndpoint()DefaultToolCallingLoopalready used a pre-resolved endpoint fromoptions.invocation.endpoint, confirming the pattern is provenFiles changed (6)
Impact
Eliminates 4 redundant
getChatEndpointcalls per tool-calling round.