Repository navigation
Add Copilot auto routing via /models/session + /models/session/intent - #1
Merged
Merged
Conversation
2 tasks done
Adds a github-copilot/auto model that follows Copilot's own auto selection: opens a per-conversation /models/session (token + pool), calls the /models/session/intent router per VS Code's cadence (route on turn 0, stick after, re-eval on compaction), and attaches Copilot-Session-Token to chat requests for the auto billing/rate-limit pool. - Within-family routing: the cloned auto model has one fixed endpoint, so routing stays in the anchored family (reasoning-vs-fast tier), with a guard ensuring the family has >=2 tiers to choose between. - Default selection mirrors VS Code's _selectDefaultModel (first same-family model in available_models), not the undocumented selected_model. - Reasoning-effort mapping: needs_reasoning raises the routed model's effort (reasoning_effort:high for OpenAI/Copilot, extended-thinking budget for Anthropic); fast turns left at default. - Picker label 'Auto'; a toast surfaces each (re)route. - CAPI headers verified against @vscode/copilot-api _mixinHeaders; the integration-id/editor-version lines are left commented (code-oss is the honest floor) to test the minimal set first.
avishefi
force-pushed
the
feat/session-intent-routing
branch
from
June 12, 2026 07:15
b7c47e0 to
1fd442a
Compare
Owner
|
Thanks! Added some other improvements afterwards. |
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.
What
Makes
github-copilot/autofollow Copilot's own auto selection — including the per-turn intent router that VS Code uses — rather than a static availability pick.The flow (reverse-engineered from
microsoft/vscode-copilot-chat+@vscode/copilot-api, verified against the lib's_mixinHeaders):POST /models/session— per-conversation: returns the candidate pool + aCopilot-Session-Token(attaching it to chat requests is what puts them in the auto billing/rate-limit pool + discount).POST /models/session/intent— the router: given the prompt, returns rankedcandidate_models(reasoning vs. fast). The only call that sees the prompt.Wired into opencode hooks:
provider.models(injectAuto),chat.message(capture prompt),chat.params(route + override model id),chat.headers(attach session token),event(re-eval on compaction).Routing behavior (mirrors VS Code)
session.compacted— matching VS Code's automode router (turnCount > 0skip +invalidateRouterCache).automodel has a single fixed endpoint (npm + url), so routing stays in the anchored family (a reasoning tier vs. a fast tier). A guard anchors on a family with ≥2 tiers so the router always has a choice. (VS Code re-instantiates the endpoint per turn and can cross families; opencode can only rewrite the model id, hence the constraint.)_selectDefaultModel— first same-family model inavailable_models— instead of the undocumentedselected_model.needs_reasoningraises the routed model's effort (reasoning_effort: highfor OpenAI/Copilot, an extended-thinking budget for Anthropic); fast turns stay at the model default.UI
Auto; a toast surfaces each (re)route (e.g.Auto → gpt-5.4 · needs_reasoning).Headers / gating
CAPI headers verified against
@vscode/copilot-api's_mixinHeaders. TheCopilot-Integration-Id/Editor-Version/Editor-Plugin-Versionlines are left commented so the minimal header set can be tested first; the honest non-impersonating floor isCopilot-Integration-Id: code-oss(what a plain OSS build sends). Note the intent router is a Team-Internal/Panel-only experiment in shipped VS Code, so this tracks internal VS Code behavior.Tests
bun test(7 pass),bun run typecheck,bun run buildall green.