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 {