refactor(agent): trim obsolete loop surfaces
This commit is contained in:
@@ -176,6 +176,14 @@ export function apply(ctx: Context, config: Config = {}, internals: RetryInterna
|
||||
retries.delete(agent)
|
||||
})
|
||||
|
||||
// A completed model response ends the consecutive-failure sequence even
|
||||
// when its tool calls keep the turn running into another request.
|
||||
ctx.on('session/event', (session, event) => {
|
||||
if (event.type !== 'assistant/message') return
|
||||
const agent = ctx.agents.get(session.id)
|
||||
if (agent?.session === session) retries.delete(agent)
|
||||
})
|
||||
|
||||
const disposeListener = ctx.on('agent/request-error', (
|
||||
agent: Agent,
|
||||
turn: number,
|
||||
|
||||
@@ -88,7 +88,9 @@ function validateRetry(
|
||||
}
|
||||
|
||||
const chainStart = retryChainStart(history, turn)
|
||||
const chainRetries = history.slice(Math.max(chainStart, 0))
|
||||
const chain = history.slice(Math.max(chainStart, 0))
|
||||
const lastSuccess = chain.findLastIndex(prior => prior.type === 'assistant/message')
|
||||
const chainRetries = chain.slice(lastSuccess + 1)
|
||||
.filter((prior): prior is SessionEvent<'llm/retry'> => prior.type === 'llm/retry')
|
||||
if (chainRetries.some(prior => prior.data.turn === turn && prior.data.step === step)) {
|
||||
fail(`llm/retry duplicates the retry record for turn ${turn}/step ${step}`)
|
||||
|
||||
Reference in New Issue
Block a user