@@ -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,使用估算;后续轮次使用真实值
@@ -669,6 +668,11 @@ IMPORTANT: Execute according to the approved plan above. Follow the steps exactl
669668 logger . debug ( '当前权限模式:' , context . permissionMode ) ;
670669 logger . debug ( '================================\n' ) ;
671670
671+ // 🆕 如果 LLM 返回了 thinking 内容(DeepSeek R1 等),通知 UI
672+ if ( turnResult . reasoningContent && options ?. onThinking ) {
673+ options . onThinking ( turnResult . reasoningContent ) ;
674+ }
675+
672676 // 🆕 如果 LLM 返回了 content,立即显示
673677 if ( turnResult . content && turnResult . content . trim ( ) && options ?. onContent ) {
674678 options . onContent ( turnResult . content ) ;
@@ -858,7 +862,7 @@ IMPORTANT: Execute according to the approved plan above. Follow the steps exactl
858862 }
859863 logger . debug ( '==================================\n' ) ;
860864
861- // 🆕 检查是否应该退出循环(ExitPlanMode 返回时设置此标记 )
865+ // 🆕 检查是否应该退出循环(ExitPlanMode 或用户拒绝时设置此标记 )
862866 if ( result . metadata ?. shouldExitLoop ) {
863867 logger . debug ( '🚪 检测到退出循环标记,结束 Agent 循环' ) ;
864868
@@ -1361,15 +1365,13 @@ IMPORTANT: Execute according to the approved plan above. Follow the steps exactl
13611365 * 在 Agent 循环中检查并执行压缩
13621366 * 仅使用 LLM 返回的真实 usage.promptTokens 进行判断(不再估算)
13631367 *
1364- * @param messages - 实际发送给 LLM 的消息数组
13651368 * @param context - 聊天上下文
13661369 * @param currentTurn - 当前轮次
13671370 * @param actualPromptTokens - LLM 返回的真实 prompt tokens(必须,来自上一轮响应)
13681371 * @param onCompacting - 压缩状态回调
13691372 * @returns 是否发生了压缩
13701373 */
13711374 private async checkAndCompactInLoop (
1372- messages : Message [ ] ,
13731375 context : ChatContext ,
13741376 currentTurn : number ,
13751377 actualPromptTokens ?: number ,
0 commit comments