feat: builtin agent session resume via deterministic message reconstruction (#426)

- StepRecord adds edgePrompt field (backward compat: defaults to "")
- StepNode CAS schema includes edgePrompt
- writeStepNode persists ctx.edgePrompt
- buildHistory exposes edgePrompt in StepContext
- buildBuiltinMessages reconstructs multi-turn moderator↔agent conversation:
  system = role prompt + output format (stable prefix)
  per prior visit: user (edgePrompt + inter-step summary) + assistant (output)
  current: user (edgePrompt + recent summary)
- Zero extra persistence — pure function of CAS chain
- Stable prefix for LLM prompt cache hits
- 10 builtin tests pass, all other package tests pass
This commit is contained in:
2026-05-23 17:34:49 +08:00
parent 9f95956e19
commit 080792a6c0
12 changed files with 305 additions and 52 deletions
@@ -7,6 +7,7 @@ const reviewerStep: StepContext = {
output: { approved: false, comments: "Missing tests" },
detail: "2MXBG6PN4A8JR",
agent: "uwf-hermes",
edgePrompt: "Review the developer's work.",
};
const developerStep: StepContext = {
@@ -14,6 +15,7 @@ const developerStep: StepContext = {
output: { filesChanged: ["src/app.ts"], summary: "Initial fix" },
detail: "1VPBG9SM5E7WK",
agent: "uwf-hermes",
edgePrompt: "Implement the fix.",
};
describe("buildContinuationPrompt", () => {
@@ -26,6 +28,7 @@ describe("buildContinuationPrompt", () => {
output: { plan: "revise approach" },
detail: "7BQST3VW9F2MA",
agent: "uwf-hermes",
edgePrompt: "Revise the plan.",
},
];
@@ -102,6 +102,7 @@ async function buildHistory(
output: expandOutput(store, step.output),
detail: step.detail,
agent: step.agent,
edgePrompt: step.edgePrompt ?? "",
});
}
return history;
+3
View File
@@ -50,6 +50,7 @@ async function writeStepNode(options: {
outputHash: CasRef;
detailHash: CasRef;
agentName: string;
edgePrompt: string;
}): Promise<CasRef> {
const payload: StepNodePayload = {
start: options.startHash,
@@ -58,6 +59,7 @@ async function writeStepNode(options: {
output: options.outputHash,
detail: options.detailHash,
agent: options.agentName,
edgePrompt: options.edgePrompt,
};
const hash = await options.store.put(options.schemas.stepNode, payload);
const node = options.store.get(hash);
@@ -95,6 +97,7 @@ async function persistStep(options: {
outputHash: options.outputHash,
detailHash: options.detailHash,
agentName: options.agentName,
edgePrompt: options.ctx.edgePrompt,
});
}