跳到正文

Baoyu 解释主会话和线程如何减少令牌用量

宝玉 · X· @dotey·· 18 小时前

3798 次浏览 · 7 赞 · 1 转发 (收录时)

原文
谁
dotey
引文
主会话 + Thread 的模式,优化好的话 Token 消耗其实还好。

发生了什么

Baoyu 表示,主会话可以使用能力较弱的模型来分配任务,而线程则使用能力更强的模型处理任务。在 Claude Project 中,Baoyu 使用 Sonnet 5.5 处理主会话,使用 Opus 5.5 处理子任务。Baoyu 还建议,主会话的缓存过期时只发送最近的消息,并在线程缓存过期前压缩上下文,例如,对于一小时的缓存,可在 50 分钟时压缩。

接下来读什么

查看这件事的完整进展Baoyu Explains Model Routing and Prompt Caching Across Main Sessions and Threads
正文

主会话 + Thread 的模式,优化好的话 Token 消耗其实还好。

首先主会话反而不需要特别强的模型,Sonnet 5.5 这个级别都够用了,因为它的主要职责是甄别和路由,或者说调度。

就跟公司前台一样,你不需要招一个专家,只要知道什么任务该找谁。

主会话里面很多任务都可以让 Thread 去完成,反倒是 Thread 应该用相对强一些的模型。当然更科学的办法是主会话在调度的时候根据任务难度去选择合适的模型。

比如我在用 Claude Project 的时候,主会话是 Sonnet 5.5,子任务是 Opus 5.5。

另外就是 Prompt Caching 的利用。

像主会话这种,特点是偶尔来个消息,很难利用好缓存,所以缓存如果过期了,不应该跟把所有历史会话和工具调用都发过去,而是只把最新的几条消息记录发过去,再配合 Session 的检索工具,可以很容易的收集齐上下文。

而对于 Thread,则是像传统的 Session 会话,会集中时间有很多对话,通常 Cache 利用率很高,但是也可能会出现缓存过期后又来新的消息,所以最佳策略是在缓存快过期的时候,比如 50 分钟(如果缓存一个小时的话)的时候,压缩一下上下文。

引用Gary Zhang@GaryZhang124

问题是,Grok bot这个如果走单主会话的交互太耗额度了。x.com/dotey/status/2121434782…

在 X 查看被引用的帖子

这件事到目前为止

Baoyu outlined how AI workflows can pair a lightweight main session for task routing with stronger models in separate threads. In Claude Project, he uses Sonnet 5.5 for the main session and Opus 5.5 for subtasks. In a GrokBot math research setup, Baoyu said the main session acts like a front desk that receives incoming messages and opens a new thread for each research request, forwarding the prompt as written. A stronger model such as Fable plans, schedules, and reviews the work, while Opus handles execution. To reduce token consumption, Baoyu recommends sending only recent messages after a main session's prompt cache expires and compressing thread context before its cache expires, such as at 50 minutes for a one-hour cache.