@@ -185,7 +185,7 @@ export class Agent {
185185 baseUrl : modelConfig . baseUrl ,
186186 temperature : modelConfig . temperature ?? this . config . temperature ,
187187 maxContextTokens : modelConfig . maxContextTokens ?? this . config . maxContextTokens , // 上下文窗口(压缩判断)
188- maxOutputTokens : this . config . maxOutputTokens , // 输出限制(API max_tokens)
188+ maxOutputTokens : modelConfig . maxOutputTokens ?? this . config . maxOutputTokens , // 输出限制(API max_tokens)
189189 timeout : this . config . timeout ,
190190 } ) ;
191191
@@ -278,8 +278,8 @@ export class Agent {
278278 : await this . runLoop ( enhancedMessage , context , loopOptions ) ;
279279
280280 if ( ! result . success ) {
281- // 如果是用户中止 ,返回空字符串(不抛出异常)
282- if ( result . error ?. type === 'aborted' ) {
281+ // 如果是用户中止或用户拒绝 ,返回空字符串(不抛出异常)
282+ if ( result . error ?. type === 'aborted' || result . metadata ?. shouldExitLoop ) {
283283 return '' ; // 返回空字符串,让调用方自行处理
284284 }
285285 // 其他错误则抛出异常
@@ -530,7 +530,6 @@ IMPORTANT: Execute according to the approved plan above. Follow the steps exactl
530530 // checkAndCompactInLoop 返回是否发生了压缩
531531 // 🆕 传入上一轮 LLM 返回的真实 prompt tokens(比估算更准确)
532532 const didCompact = await this . checkAndCompactInLoop (
533- messages ,
534533 context ,
535534 turnsCount ,
536535 lastPromptTokens , // 首轮为 undefined,使用估算;后续轮次使用真实值
@@ -863,7 +862,7 @@ IMPORTANT: Execute according to the approved plan above. Follow the steps exactl
863862 }
864863 logger . debug ( '==================================\n' ) ;
865864
866- // 🆕 检查是否应该退出循环(ExitPlanMode 返回时设置此标记 )
865+ // 🆕 检查是否应该退出循环(ExitPlanMode 或用户拒绝时设置此标记 )
867866 if ( result . metadata ?. shouldExitLoop ) {
868867 logger . debug ( '🚪 检测到退出循环标记,结束 Agent 循环' ) ;
869868
@@ -1366,15 +1365,13 @@ IMPORTANT: Execute according to the approved plan above. Follow the steps exactl
13661365 * 在 Agent 循环中检查并执行压缩
13671366 * 仅使用 LLM 返回的真实 usage.promptTokens 进行判断(不再估算)
13681367 *
1369- * @param messages - 实际发送给 LLM 的消息数组
13701368 * @param context - 聊天上下文
13711369 * @param currentTurn - 当前轮次
13721370 * @param actualPromptTokens - LLM 返回的真实 prompt tokens(必须,来自上一轮响应)
13731371 * @param onCompacting - 压缩状态回调
13741372 * @returns 是否发生了压缩
13751373 */
13761374 private async checkAndCompactInLoop (
1377- messages : Message [ ] ,
13781375 context : ChatContext ,
13791376 currentTurn : number ,
13801377 actualPromptTokens ?: number ,
0 commit comments