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. */
|
/** 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 {
|
export class ReactLoopAgent implements Agent {
|
||||||
readonly inbox: Inbox
|
readonly inbox: Inbox
|
||||||
private phase: Phase
|
private phase: Phase
|
||||||
@@ -293,7 +279,14 @@ export class ReactLoopAgent implements Agent {
|
|||||||
turnEnds = { kind: 'aborted', reason: signal.reason as AgentCancelCause }
|
turnEnds = { kind: 'aborted', reason: signal.reason as AgentCancelCause }
|
||||||
throw error
|
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)
|
this.throwError(error)
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user