Skip to content

Resolve endpoint once per tool-calling round instead of per-method#5031

Open
abadawi591 wants to merge 4 commits intomicrosoft:mainfrom
abadawi591:abadawi/resolve-endpoint-once-per-round
Open

Resolve endpoint once per tool-calling round instead of per-method#5031
abadawi591 wants to merge 4 commits intomicrosoft:mainfrom
abadawi591:abadawi/resolve-endpoint-once-per-round

Conversation

@abadawi591
Copy link
Copy Markdown

@abadawi591 abadawi591 commented Apr 7, 2026

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 automodeService to prevent duplicate telemetry. This PR eliminates the redundant getChatEndpoint calls at the source.

Problem

runOne() in toolCallingLoop.ts calls getChatEndpoint(request) up to 5 times per round via getAvailableTools, buildPrompt, token counting, and fetch. All calls return the same endpoint for the same round. This dates back to the initial repo (af813ee)

  • Add resolveEndpoint() to the base ToolCallingLoop, called once at the top of runOne()
  • Pass the resolved endpoint to buildPrompt, getAvailableTools, and fetch as a parameter
  • Each subclass's private getEndpoint() becomes an override of resolveEndpoint()
  • DefaultToolCallingLoop already used a pre-resolved endpoint from options.invocation.endpoint, confirming the pattern is proven

Files changed (6)

File Change
toolCallingLoop.ts Add resolveEndpoint(), add endpoint param to 3 abstract methods, resolve once in runOne()
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 (continues using invocation.endpoint)

Impact

Eliminates 4 redundant getChatEndpoint calls per tool-calling round.

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)
Copilot AI review requested due to automatic review settings April 7, 2026 07:47
Copy link
Copy Markdown
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 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() to ToolCallingLoop and resolved the endpoint once at the start of runOne().
  • Updated ToolCallingLoop abstract method signatures to accept the resolved IChatEndpoint, and updated concrete loops to match.
  • Migrated subagent/codebase/MCP loops from per-method endpoint resolution (getEndpoint()) to resolveEndpoint() 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

Comment thread src/extension/prompt/node/searchSubagentToolCallingLoop.ts Outdated
Comment thread src/extension/mcp/vscode-node/mcpToolCallingLoop.tsx Outdated
Comment thread src/extension/intents/node/toolCallingLoop.ts
Comment thread src/extension/prompt/node/defaultIntentRequestHandler.ts
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.
@pwang347 pwang347 assigned lramos15 and unassigned pwang347 Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants