-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: support Magistral [THINK]...[/THINK] reasoning tags #8523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- Created new SquareBracketMatcher class to handle square bracket syntax - Updated native-ollama provider to detect Magistral models and use appropriate matcher - Added comprehensive tests for square bracket matching functionality - Maintains backward compatibility with existing XML-style <think> tags Fixes #8522
| constructor( | ||
| readonly tagName: string, | ||
| readonly transform?: (chunks: SquareBracketMatcherResult) => Result, | ||
| readonly position = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor accepts a 'position' parameter which is never used. Consider removing it or adding a comment to document its intended purpose.
| readonly position = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performing self-review: the robot audits itself and promises it’s unbiased this time.
| } | ||
|
|
||
| private processComplete() { | ||
| const openTag = `[${this.tagName}]` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P1] Matching is case-sensitive. If a Magistral variant emits [think]...[/think], this matcher won’t detect it. Consider normalizing both buffer and tag to a common case during search (for example, use lowercased copies for index lookups while slicing from the original string), or add an optional caseInsensitive flag.
| constructor( | ||
| readonly tagName: string, | ||
| readonly transform?: (chunks: SquareBracketMatcherResult) => Result, | ||
| readonly position = 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P3] Unused constructor parameter position increases noise and suggests capabilities that aren’t implemented. Remove it or implement position-aware matching.
Summary
This PR fixes the issue where Magistral model's reasoning tags using square bracket syntax
[THINK]...[/THINK]were not being properly recognized by Roo Code when using Ollama.Problem
Magistral models use a different syntax for reasoning blocks compared to other models:
<think>...</think>(XML-style)[THINK]...[/THINK](square bracket style)The existing XmlMatcher only handled XML-style tags, causing Magistral's reasoning content to be displayed as regular text.
Solution
SquareBracketMatcherclass that handles square bracket syntaxChanges
src/utils/square-bracket-matcher.ts- Handles[TAG]...[/TAG]syntaxsrc/api/providers/native-ollama.ts- Conditionally uses SquareBracketMatcher for Magistral modelssrc/utils/__tests__/square-bracket-matcher.spec.ts- 12 test cases covering all edge casesTesting
Screenshots
As shown in the issue, Magistral's reasoning tags are now properly recognized and hidden from the output.
Fixes #8522
Important
Adds
SquareBracketMatcherfor[THINK]...[/THINK]tags in Magistral models and updatesNativeOllamaHandlerto use it.SquareBracketMatcherto handle[THINK]...[/THINK]tags insquare-bracket-matcher.ts.NativeOllamaHandlerinnative-ollama.tsto useSquareBracketMatcherfor Magistral models.square-bracket-matcher.spec.tswith 12 test cases forSquareBracketMatchercovering edge cases.XmlMatcherfunctionality.This description was created by
for 6de1c6e. You can customize this summary. It will automatically update as commits are pushed.