Skip to content

Add LLM reasoning traces#457

Open
Daniel5055 wants to merge 8 commits intoNano-Collective:mainfrom
Daniel5055:feature/reasoning-trace
Open

Add LLM reasoning traces#457
Daniel5055 wants to merge 8 commits intoNano-Collective:mainfrom
Daniel5055:feature/reasoning-trace

Conversation

@Daniel5055
Copy link
Copy Markdown

@Daniel5055 Daniel5055 commented Apr 15, 2026

Description

This PR adds reasoning traces for thinking LLMs, as proposed in #341. When a model begins reasoning, the user is informed with a Thinking message. If the 'expand tool results' option is toggled, the full reasoning text is displayed.

Reasoning text is streamed to the user like regular responses, and preserved in the chat history. The following video demonstrates how the reasoning appears expanded and then compacted.

Screencast_20260415_141539.webm

Implementation Details

Model reasoning is accessed via the Vercel AI SDK. The reasoning stream is stored and rendered separately from the text stream. Once finished streaming, the reasoning remains as a live component in the chat history until the text stream is finished. Then the reasoning is added to the chat history together with the text as to ensure the correct ordering.

Potential Improvements

  • Instead of relying on the 'expand tool results' option, reasoning traces could depend on a new option + key binding if needed.
  • Ideally, reasoning should be added to the chat history right after its stream finishes. However, the live tools display means the tool calls are added to the chat history later on, leading to reasoning appearing out of order with tool calls.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging (see CONTRIBUTING.md)

@Daniel5055
Copy link
Copy Markdown
Author

Regarding testing, I manually tested the feature with Ollama and llama.cpp as providers, and used local models with reasoning and no reasoning. I did not test with OpenRouter because I do not pay for any models.

I am happy to refine this feature further if you have any feedback or suggestions!

@Avtrkrb
Copy link
Copy Markdown
Member

Avtrkrb commented Apr 15, 2026

Improvements

  • Instead of relying on the 'expand tool results' option, reasoning traces could depend on a new option + key binding if needed.
  • Ideally, reasoning should be added to the chat history right after its stream finishes. However, the live tools display means the tool calls are added to the chat history later on, leading to reasoning appearing out of order with tool calls.

@Daniel5055
This is great ! Thanks for this. Just a question, are the points which you have mentioned in the Improvements section your proposals for Improvements or have you already implemented them ? Please clarify...

IMHO I agree with your point of having a new option + key binding for toggling the reasoning traces as this provides a much cleaner UX & separates concerns w.r.t keybindings. If this is not yet part of the PR, go for it ! 👍

You have a valid 2nd point as well... Again if you have the fix for it, please go ahead (assuming it's not already a part of the PR)

@will-lamerton what do you think ?

I just eyeballed the PR & it looks good to me, will take a deeper look sometime soon.. but awesome stuff !

@Avtrkrb
Copy link
Copy Markdown
Member

Avtrkrb commented Apr 15, 2026

I did not test with OpenRouter because I do not pay for any models.

Openrouter hosts a few free models: https://openrouter.ai/models?max_price=0

I think the Gemma 4 model from your screencast video is also free in Openrouter as of this writing, it would be helpful if you could test with any free tier models on Openrouter as well.

I'm happy to test as well if you'd like👍.

@Daniel5055
Copy link
Copy Markdown
Author

Daniel5055 commented Apr 15, 2026

Thanks! I meant the improvements section to reflect potential changes that could be made.

The second point was more open ended, and I don't have a better solution unfortunately for now.

But you make a good point for a separate option and key binding, and I'll look into implementing it 👍

Ah I didn't know about free models on OpenRouter. I'll do some manual testing with it then too.

@will-lamerton
Copy link
Copy Markdown
Member

This looks excellent @Daniel5055 - love the design choices as well. I'll review the code properly later and if all is good I'll merge. 😎

Avtrkrb
Avtrkrb previously approved these changes Apr 16, 2026
@Avtrkrb
Copy link
Copy Markdown
Member

Avtrkrb commented Apr 16, 2026

@Daniel5055 changes look good to me.
I would appreciate if you could implement the dedicated keybind + option for toggling the reasoning traces in this PR itself since you seem to have a handle on it !

For the 2nd point you mentioned I guess it's fine if you don't currently have an implementation approach, but do try to create an issue for it if you can..that way we can tackle it in a future date !

@Daniel5055
Copy link
Copy Markdown
Author

@Avtrkrb I have implemented an option for expanding reasoning traces which can be configured in the preferences file. It can also be toggled dynamically with the Ctrl-R keybind. By default reasoning traces are not expanded. Let me know if you want any tweaks to this.

I also tested the feature with OpenRouter using free reasoning and non-reasoning models, and it works as expected 👍

@Avtrkrb
Copy link
Copy Markdown
Member

Avtrkrb commented Apr 17, 2026

@Avtrkrb I have implemented an option for expanding reasoning traces which can be configured in the preferences file. It can also be toggled dynamically with the Ctrl-R keybind. By default reasoning traces are not expanded. Let me know if you want any tweaks to this.

I also tested the feature with OpenRouter using free reasoning and non-reasoning models, and it works as expected 👍

This is awesome !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants