opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: add reasoning middleware

Open snipeship opened this issue 3 months ago • 6 comments

Closes #6337, #4033, #3703


Adds a new interleaved object shape to model config with tagName (required) and optional startWithReasoning. Read ai-sdk's extractReasoningMiddleware() as a reference.

Example config:

"models": {
  "model-name": {
    "reasoning": true,
    "interleaved": {
      "tagName": "think" // or other XML tag
      // "startWithReasoning": true
    },
  }
}

Before (see issue)

After: Screenshot 2025-12-29 at 10 14 57

snipeship avatar Dec 29 '25 08:12 snipeship

as discussed here: https://discord.com/channels/1391832426048651334/1394667004979445931/1455066042056441982 cc @rekram1-node

snipeship avatar Dec 29 '25 08:12 snipeship

wondering if there is anyway we could avoid additional configs and just always have it on, and then default to handling which should cover 90% of users and they wont have to do configs manually?

rekram1-node avatar Dec 30 '25 03:12 rekram1-node

wondering if there is anyway we could avoid additional configs and just always have it on, and then default to handling which should cover 90% of users and they wont have to do configs manually?

opened #6463 doesn't close https://github.com/sst/opencode/issues/3703 because of the different thinking tags guess if there are more users facing this issue (or labs being annoying), we can revisit this solution with some logic from the other PR (on by default, change thinking tags, or disable the middleware through config)

snipeship avatar Dec 30 '25 19:12 snipeship

 "models": {
        "minimax": {
          "name": "minimax",
          "tool_call": true,
          "reasoning": true,
          "interleaved": {
            "tagName": "think"
          },
image_2026-01-09_01-43-12

Do I need to pull a specific issue from the repository, or am I missing something?

letsrock85 avatar Jan 09 '26 07:01 letsrock85

 "models": {
        "minimax": {
          "name": "minimax",
          "tool_call": true,
          "reasoning": true,
          "interleaved": {
            "tagName": "think"
          },
image_2026-01-09_01-43-12 Do I need to pull a specific issue from the repository, or am I missing something?

it should work by default now on the latest build without adding anything to the config. if for some reason you need custom think tags (looks like you don’t) you can build from source from this branch

snipeship avatar Jan 09 '26 07:01 snipeship

I use VS Code opencode extension on Windows, last updated 3 days ago, it throws an error when I add "interleaved": { "tagName": "think" }. " which I need for Opencode to properly parse minimax-m2's tag. image

letsrock85 avatar Jan 09 '26 20:01 letsrock85