Files
agent-loop/research/t3-code-async-agent-loop.md
2026-11-12 15:29:12 +08:00

14 lines
4.0 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# T3 Code 与异步 Agent Loop
T3 Code 的源码核对固定在 2026 年 11 月 11 日查询到的 `main` 提交 `a536ff7`。下面描述的是代码和文档中的行为,现场交互时序待实测。 [T3 Code 提交](https://github.com/pingdotgg/t3code/commit/a536ff7ac0c080190f098965d0a0d244caf5b211)
DeepSeek 设计文章第 4.1 节把耗时工具拆成启动和完成两次交互。启动先返回,Agent Loop 在当前推理步结束后可以处理新消息,后台任务结束时再把结果交回原会话。公开原型的 Worker 会把超过 5 秒的 shell 命令转到后台,并用完成结果唤醒 Worker。 [文章第 4.1 节](https://xitter.cf/DeepSeekHarness/article/2116857257245987236#:~:text=4.1%20Full%2DDuplex)、[原型执行文档](https://github.com/deepseek-ai/dsh-superagent-prototype/blob/6337fc823ce20251c8de8085948165c81aaa701e/docs/003-execution.md#the-executor)
T3 Code 把客户端线程接到 Codex、Claude Code 等现成运行时,由 T3 服务端管理消息与运行状态。忙时发送有两个选项。**Queue** 把消息保存在服务端,等后续 turn。**Steer** 把新消息送给当前 turn,对 Codex 会发 `turn/steer`,并带上目标 turn 的 ID。发送成功和模型何时处理属于两个时间点。 [项目定位](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/README.md#L1-L9)、[Queue 与 Steer](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/docs/user/composer.md#L63-L80)、[消息分发](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/apps/server/src/orchestration-v2/ThreadManagementService.ts#L844-L853)、[Codex 原生 steering](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts#L7474-L7504)
**Claude 的实现说明了为什么同一个 Steer 按钮会有不同语义。** 适配器声明主动 steering 可能中断前台工具。在发送 `priority: "now"` 之前,它先尝试通过 SDK 把符合条件的前台子 Agent 移到后台,这一步有 5 秒预算。能否保留在途工作取决于 provider、工作类型和转入后台的结果。 [Claude 能力声明](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts#L420-L429)、[后台迁移及消息投递](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts#L11664-L11803)
**后台结果唤醒才是和原文最接近的一段。** 比如 Codex 某些后台命令在根 turn 已结束后完成,适配器会在满足状态和去重检查时,将退出状态和输出摘要作为 continuation 提交。T3 的服务把它变成同一线程的内部消息,走 `queue_after_active`。适配器也报告待完成的后台工作,让服务端延后回收看似空闲的 provider 会话。 [Codex 命令摘要](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts#L446-L470)、[完成后请求 continuation](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts#L5179-L5238)、[同线程投递](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/apps/server/src/orchestration-v2/ProviderContinuationService.ts#L182-L205)、[空闲回收](https://github.com/pingdotgg/t3code/blob/a536ff7ac0c080190f098965d0a0d244caf5b211/apps/server/src/orchestration-v2/ProviderSessionManager.ts#L1182-L1238)
周五可以用 T3 Code 的 Queue 和 Steer 开场,再用既定的本地测试演示把三件事落在时间线上。消息何时被接收、何时被模型处理、后台命令何时结束并交回结果。DeepSeek 讲的是 Loop 怎样让长工具让出执行机会,T3 Code 的代码展示了上层产品怎样接住不同 provider 提供的能力。