From f0622f3280105199c73f94d6fb2546a7466e7e0b Mon Sep 17 00:00:00 2001 From: _Kerman Date: Mon, 3 Aug 2026 16:43:45 +0800 Subject: [PATCH] refactor(agent-loop): inline the turn error shaping --- packages/core/agent-loop/src/agent.ts | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/packages/core/agent-loop/src/agent.ts b/packages/core/agent-loop/src/agent.ts index b9d3217419..8983a13551 100644 --- a/packages/core/agent-loop/src/agent.ts +++ b/packages/core/agent-loop/src/agent.ts @@ -60,20 +60,6 @@ function requestProposal(header: EpochHeader): LlmCallConfig { } /** Drives one session through turn and step boundaries. */ -/** - * Shape a caught turn error into its durable reason: every failure is a - * structured LlmFailure — an `LlmError` keeps its facts, anything else - * flattens to `errorChain` text under the `UNKNOWN` code. - */ -function turnErrorReason(error: unknown): Extract { - return { - kind: 'error', - error: error instanceof LlmError - ? error.failure - : { message: errorChain(error), code: 'UNKNOWN' }, - } -} - export class ReactLoopAgent implements Agent { readonly inbox: Inbox private phase: Phase @@ -293,7 +279,14 @@ export class ReactLoopAgent implements Agent { turnEnds = { kind: 'aborted', reason: signal.reason as AgentCancelCause } throw error } - turnEnds = turnErrorReason(error) + // Every failure is structured: an `LlmError` keeps its facts, anything + // else flattens to `errorChain` text under the `UNKNOWN` code. + turnEnds = { + kind: 'error', + error: error instanceof LlmError + ? error.failure + : { message: errorChain(error), code: 'UNKNOWN' }, + } this.throwError(error) } finally { try {