From efed4dee036b5a5c894d790c8e2c128945b08178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Thu, 28 May 2026 00:39:44 +0000 Subject: [PATCH] fix(agent): trim leading whitespace from agent output before frontmatter extraction Fixes #567 --- packages/workflow-util-agent/src/run.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/workflow-util-agent/src/run.ts b/packages/workflow-util-agent/src/run.ts index b6d08f6..ecb139d 100644 --- a/packages/workflow-util-agent/src/run.ts +++ b/packages/workflow-util-agent/src/run.ts @@ -151,6 +151,7 @@ export function createAgent(options: AgentOptions): () => Promise { const startedAtMs = Date.now(); let agentResult = await runWithMessage("agent run failed", () => options.run(ctx)); + agentResult.output = agentResult.output.trimStart(); // Preserve the primary detail from the first run — it contains the full // tool-call turn history. Continuation retries only fix frontmatter @@ -169,6 +170,7 @@ export function createAgent(options: AgentOptions): () => Promise { agentResult = await runWithMessage("agent continue failed", () => options.continue(agentResult.sessionId, correctionMessage, ctx.meta.store), ); + agentResult.output = agentResult.output.trimStart(); extracted = await tryExtractOutput(agentResult.output, roleDef.frontmatter, ctx); }