refactor(agent-loop): inline the turn error shaping
This commit is contained in:
@@ -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<TurnEndReason, { kind: 'error' }> {
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user