fix: preserve agent context during compaction (#4556)

This commit is contained in:
Patrick Wolf
2025-11-21 00:13:10 -08:00
committed by GitHub
parent e018e16898
commit 416f2964b5
3 changed files with 17 additions and 3 deletions

View File

@@ -813,8 +813,18 @@ export namespace Server {
async (c) => {
const id = c.req.valid("param").id
const body = c.req.valid("json")
const msgs = await Session.messages({ sessionID: id })
let currentAgent = "build"
for (let i = msgs.length - 1; i >= 0; i--) {
const info = msgs[i].info
if (info.role === "user") {
currentAgent = info.agent || "build"
break
}
}
await SessionCompaction.create({
sessionID: id,
agent: currentAgent,
model: {
providerID: body.providerID,
modelID: body.modelID,