From 759c7842674d1d0f0d7e376fe7f19467e695c0d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Sat, 23 May 2026 14:02:51 +0000 Subject: [PATCH] fix: preserve primary detail hash across frontmatter retries When the agent's first run output fails frontmatter extraction, the retry loop (via options.continue) would replace agentResult entirely, causing the 1-turn continuation detail to overwrite the original multi-turn detail containing all tool-call history. Now we capture primaryDetailHash from the first run and always use it for the persisted StepNode, regardless of how many retries occur. Fixes #439 --- packages/workflow-agent-kit/src/run.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/workflow-agent-kit/src/run.ts b/packages/workflow-agent-kit/src/run.ts index 552a6da..2a3d8fb 100644 --- a/packages/workflow-agent-kit/src/run.ts +++ b/packages/workflow-agent-kit/src/run.ts @@ -121,6 +121,11 @@ export function createAgent(options: AgentOptions): () => Promise { let agentResult = await runWithMessage("agent run failed", () => options.run(ctx)); + // Preserve the primary detail from the first run — it contains the full + // tool-call turn history. Continuation retries only fix frontmatter + // formatting and their 1-turn detail is not meaningful. + const primaryDetailHash = agentResult.detailHash; + // Try to extract frontmatter; retry via continue if it fails let outputHash = await tryExtractOutput(agentResult.output, roleDef.frontmatter, ctx); @@ -147,7 +152,7 @@ export function createAgent(options: AgentOptions): () => Promise { const stepHash = await persistStep({ ctx, outputHash, - detailHash: agentResult.detailHash, + detailHash: primaryDetailHash, agentName: agentLabel(options.name), });