github / github/copilot-sdk

Responses API should support native `previous_response_id` chaining

未关闭
#2,184 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
enhancement
主要语言
Java
星标
10.5k
派生
1.5k
平均合并
1 天 11 小时
30 天内合并 PR
128

描述

### Summary

When using the Copilot SDK/CLI with the Responses API, every model round reconstructs and sends the complete conversation history. The runtime does not send `previous_response_id` and sets `store: false`.

This substantially increases request tokens for long-running and resumed sessions.

### Versions tested

- `GitHub.Copilot.SDK` 1.0.5 with Copilot CLI 1.0.73
- `GitHub.Copilot.SDK` 1.0.9-preview.1 with Copilot CLI 1.0.74
- Azure AI Foundry OpenAI-compatible provider
- `wireApi: responses`

The preview SDK references CLI `1.0.76-5`, but that package was not available for testing.

### Observed behavior

A privacy-safe request probe showed:

- Initial request: 1 input item
- Tool continuation: 3 input items
- Next user turn: 5 input items
- Resumed session in a new process: 7 input items

No request included `previous_response_id`. The runtime also emitted `store: false`.

In a real long-running session, this resulted in approximately 26K–28K reported input tokens per request, including tool continuations.

### Expected behavior

After the initial Responses request:

1. Set `store: true`, or otherwise use provider-supported response retention.
2. Capture the terminal response ID.
3. Send subsequent model rounds with:
- `previous_response_id`
- only newly added input items
4. Preserve instructions, tools, and request settings as required by the Responses API.
5. Fall back to full history if the provider rejects or cannot resolve the response ID.

This should apply to both tool-result continuations and subsequent user turns.

### Workaround validation

We implemented an experimental request handler that:

- changes `store: false` to `store: true`,
- captures IDs from terminal SSE response events,
- adds `previous_response_id`,
- replaces reconstructed history with incremental input,
- falls back to full history when chaining cannot be verified.

Live validation reduced:

- a tool continuation from 60 input items to 1,
- a subsequent user turn from 66 input items to 1.

Conversation context and tool behavior remained correct.

The handler also had to account for non-semantic differences when the CLI reconstructed response items:

- regenerated top-level response item `id`,
- omitted assistant-message `phase`,
- omitted output-text `logprobs`.

Semantic content and tool `call_id` values were still compared exactly.

### Request

Could native Responses API chaining be added to the Copilot CLI/runtime and exposed or enabled through the SDK?

It would also be useful to clarify:

- whether the SDK’s `PreviousResponseId` protocol field is currently used by any provider path,
- how response IDs should persist across SDK session resumes or process restarts,
- whether token telemetry can report the actual rewritten wire input rather than reconstructed local history.

贡献指南

打开贡献指南

调研方向

首先跟踪 Responses API 的请求路径和 SDK 的协议字段 PreviousResponseId,然后比较工具延续、后续用户轮次和恢复的会话。完成标准是:受支持的提供商使用保留的响应 ID 和增量输入,保留必要的设置,在链接失败时回退到完整历史记录,并确保上下文和工具行为正确。

由索引模型根据 Issue 内容生成。

评估

领域
api, backend-api-design, cli
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
活跃
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。