[PR #4933] feat: improve session loop for reasoning models #11178

Closed
opened 2026-02-16 18:15:58 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4933

State: closed
Merged: No


Improve the session prompt loop to properly support AI models that separate their reasoning process from final responses, with specific focus on interleaved thinking patterns where reasoning, tool calls, and text are mixed.

  • Changed lastAssistant type from MessageV2.Assistant to MessageV2.WithParts to access full message structure including parts
  • Added detection for reasoning blocks vs text content in assistant messages
  • Enhanced loop exit conditions to distinguish between reasoning-only vs reasoning+text/tool content for interleaved thinking models
  • Added comprehensive comments explaining complex exit conditions
  • Supports separated thinking, interleaved thinking, and mixed tool call patterns
  • Prevents premature loop termination for models with mixed content types

This enables proper handling of interleaved thinking models like MiniMax M2 that may output reasoning blocks interspersed with tool calls and text content, ensuring the loop continues until a complete response with actual text is available.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4933 **State:** closed **Merged:** No --- Improve the session prompt loop to properly support AI models that separate their reasoning process from final responses, with specific focus on interleaved thinking patterns where reasoning, tool calls, and text are mixed. * Changed lastAssistant type from MessageV2.Assistant to MessageV2.WithParts to access full message structure including parts * Added detection for reasoning blocks vs text content in assistant messages * Enhanced loop exit conditions to distinguish between reasoning-only vs reasoning+text/tool content for interleaved thinking models * Added comprehensive comments explaining complex exit conditions * Supports separated thinking, interleaved thinking, and mixed tool call patterns * Prevents premature loop termination for models with mixed content types This enables proper handling of interleaved thinking models like MiniMax M2 that may output reasoning blocks interspersed with tool calls and text content, ensuring the loop continues until a complete response with actual text is available.
yindo added the pull-request label 2026-02-16 18:15:58 -05:00
yindo closed this issue 2026-02-16 18:15:58 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11178