You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
建议:排队消息应合并成一次处理(现在 N 条积压 = N 个完整回合,实测 98% 的 token 花在重发历史上)
#940
跨 work 的请求不能合并:它们的答复要回到不同的上游,路由会串。建议只合并「同一 work 或都无 work」的请求。
用户的消息不参与合并(用户优先级独立,且用户不该等),只合并 Bot / 群队列。
合并后回复质量有风险:一次要处理多件事,模型可能漏答。建议在 system 侧给一句硬要求:「本回合的每一条都必须答复,答复时点明是回哪一条」,并在测试里覆盖「3 条进、3 条各自有条目答复」。
English summary: In a multi-Bot team, messages that queue up in a Bot's next-turn inbox are taken out one at a time, so N queued messages cost N full turns — each re-sending the whole history, which is where the token blow-up comes from (measured: 98.1% of a day's tokens were cacheRead). The only merge that exists is for same-sender requests (tools.js:108, tools.js:237). Proposal: claim all pending "needs a reply" requests as one turn's trigger set, keep per-message exchangeId reply routing, add queueBatch / queueBatchMaxWaitMs / queueBatchMax options.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
排队消息应合并成一次处理:现在 N 条积压消息要跑 N 个完整回合
一句话
同一个 Bot 收件箱里已经排队的多条消息(next-turn 队列),出队时是一条消息一个完整回合。多 Bot 协作时这会让轮数和上下文长度相乘:每条排队消息都要重发一遍整段历史,模型也只能一条一条地看,于是互相发同样意思的消息、越积越多。建议在出队时按收件箱合并成一次处理。
现场数据(真实用量,不是估算)
我这边跑一支 5 个 Bot 的小团队。某一天的项目总量:
cacheRead 是 input 的 60 倍。单会话的 cacheRead 经常是它 input 的 50–100 倍,也就是每一轮都在重发整段历史。真正把量顶上去的不是单轮多贵,是「轮数 × 上下文长度」。而排队消息一条一个回合,正是在同时抬高这两个因子。
排队积压的规模不是理论值:一次实测里,一个正在跑长回合的 Bot 收件箱积了 19 条未读,集中在 7 分钟内,来自 4 个不同成员。其中明显是回声的:两个成员连发「收到,停手」「收到,收工」(零信息量);另一个成员三条说的是同一件事,第 5 条自己写着「这条上一轮已经答过了」。
源码实证(DS Bot 0.2.7,DSH 0.2.1-rc.5)
1. 回合结束时会为每条未答请求各开一个新回合
ds-bot/src/host/turns.js:1024-1045,turn/end的处理里:每条
deferred消息都是一条新的 user message,各自触发一个回合。2. 空闲时到达的多条消息,各自成为一次触发
ds-bot/src/host/turns.js:772-795:entry.turn === undefined时消息进entry.pending;已经有回合在跑时才走 join 分支。所以一个空闲 Bot 收到三条消息,就是三次独立触发,不是一次。3. 唯一的合并逻辑只对「同一个发信人」生效
ds-bot/src/host/tools.js:108-115:tools.js:237-252用它做「发信人还没读我前一条,就合并」——判据是source.senderSessionId === senderId,而且还要rt.sameWork(...)。不同成员发来的消息永远不会合并,而这恰恰是团队协作里的绝大多数。合并后deliver也只是把文本拼进同一条消息(delivery.js:108,merged只影响 exchange 记录)。4. 投递层只有两个粒度,没有批量出队
ds-bot/src/host/delivery.js:95-96:followup就是 DSH 的 next-turn 队列。出队那一步是 DSH 每轮取一条,DS Bot 侧没有任何合并动作。建议
核心一条:回合开始时,把收件箱里所有「需要答复」的排队请求作为同一个回合的 trigger 集合一次性取走。
现有结构基本够用,不需要新造概念:
turns.js已经有entry.joined(回合进行中落进来的请求)和claimTrigger。排队请求也可以按同样方式一次性 claim 多条,而不是一条一条 claim。拼成一条带分节的输入,例如:
答复路由保持原样:每条仍在
state.exchanges里保留自己的exchangeId,结束时按条答复;或者合并成一条答复,但逐条点名答了哪几条(后者更省,但要保证不发漏)。群聊路径要分开说:
groups.js:506是steer: busy,成员正在跑回合时消息会切进去([Feature] 群聊编排层缺少向工作中成员的“插话”(steer)投递能力——消息只能排队,无人能在其运行中触达它 #527 的成果,0.2.3 起);但成员空闲时busy === false,仍然走followup落队列,几条 @ 就是几次独立触发。要合的是后者。可配项(默认值建议保守):
queueBatch:开/关,默认开。queueBatchMaxWaitMs:出队前最多再多等这么久(建议 2000–3000ms),让同一波消息落进同一个批次,避免「刚出队就又来一条」。queueBatchMax:单批上限(比如 8),超过的留到下一批,防止一条输入被拼得超长。与已有讨论的关系(不重复)
edit_queued_message证明了「直接改写队列表项」在 DSH 上是可行的(inbox.replace()),正是本建议需要的能力基础。代价与边界
queueBatchMaxWaitMs。这个交换在团队场景下应该划算,但需要可关。English summary: In a multi-Bot team, messages that queue up in a Bot's next-turn inbox are taken out one at a time, so N queued messages cost N full turns — each re-sending the whole history, which is where the token blow-up comes from (measured: 98.1% of a day's tokens were cacheRead). The only merge that exists is for same-sender requests (
tools.js:108,tools.js:237). Proposal: claim all pending "needs a reply" requests as one turn's trigger set, keep per-messageexchangeIdreply routing, addqueueBatch/queueBatchMaxWaitMs/queueBatchMaxoptions.All reactions