microsoft / microsoft/vscode

Expose `turnId` to `LanguageModelChatProvider.provideLanguageModelChatResponse()`

Open
#332,597 1 comment 0 reactions 1 assignee Claimed by @vritant24 View on GitHub
feature-request model-byok
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

Language model providers registered through `LanguageModelChatProvider` need a stable identifier for the current user turn, but `ProvideLanguageModelChatResponseOptions` does not currently expose the internal `turnId`.

This is distinct from conversation/session identity. A conversation ID identifies the whole chat, while a turn ID should remain stable across all model calls that belong to one user turn (including tool-call continuations) and change when the next user turn begins.

### Why this is needed

BYOK/custom endpoint providers can now preserve conversation-level identity, which makes it possible to correlate requests belonging to the same chat. However, the provider still cannot reliably distinguish these two cases:

```text
User turn A
model request
tool call
tool result -model request
model request

User turn B
model request
```

From the provider side, heuristics based on message history or request ordering cannot reliably determine whether another model request is a continuation within the current turn or the start of a new turn. Retries, compaction/background requests, subagents, and tool loops make such inference fragile.

Some model backends also have explicit turn-scoped metadata/state. For example, a provider or local gateway implementing a Responses-compatible backend may need to map VS Code's user-turn lifetime onto backend `turn_id` metadata while independently preserving conversation/thread identity.

### Proposed change

Expose the existing VS Code turn identity on `ProvideLanguageModelChatResponseOptions`, for example:

```ts
export interface ProvideLanguageModelChatResponseOptions {
// existing fields...
readonly turnId?: string;
}
```

Expected semantics:

* Stable for all language model calls belonging to the same user turn.
* Reused across tool-call / tool-result continuation requests within that turn.
* Different for the next user turn.
* Passed through to BYOK/custom `LanguageModelChatProvider` implementations without requiring the provider to infer it from message history.

VS Code already tracks a turn identifier internally in the chat/model request pipeline, so this would primarily expose information that already exists at the provider boundary.

### Related issue

#305853 requests exposing chat-session identity to language model providers. This request is complementary rather than a duplicate: session/conversation identity answers **which chat?**, while `turnId` answers **which user turn within that chat?**.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.