File tree Expand file tree Collapse file tree 1 file changed +13
-1
lines changed
packages/agent-runtime/src Expand file tree Collapse file tree 1 file changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,17 @@ export const runAgentStep = async (
396396 call . toolName === 'task_completed' || call . toolName === 'end_turn' ,
397397 )
398398
399+ // If the response is only <think>...</think> tags with no other non-whitespace content,
400+ // the model was just thinking and should continue rather than end its turn.
401+ const responseWithoutThinkTags = fullResponse
402+ . replace ( / < t h i n k > [ \s \S ] * ?< \/ t h i n k > / g, '' )
403+ . replace ( / < t h i n k > [ \s \S ] * $ / , '' )
404+ . trim ( )
405+ const isThinkOnly =
406+ hasNoToolResults &&
407+ responseWithoutThinkTags . length === 0 &&
408+ fullResponse . trim ( ) . length > 0
409+
399410 // If the agent has the task_completed tool, it must be called to end its turn.
400411 const requiresExplicitCompletion =
401412 agentTemplate . toolNames . includes ( 'task_completed' )
@@ -408,7 +419,8 @@ export const runAgentStep = async (
408419 shouldEndTurn = hasTaskCompleted
409420 } else {
410421 // For other models, also end turn when there are no tool calls
411- shouldEndTurn = hasTaskCompleted || hasNoToolResults
422+ // Exception: if the response is only <think> tags, continue the turn
423+ shouldEndTurn = hasTaskCompleted || ( hasNoToolResults && ! isThinkOnly )
412424 }
413425
414426 agentState = {
You can’t perform that action at this time.
0 commit comments