Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Oct 5, 2025

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:

  • Other models: <think>...</think> (XML-style)
  • Magistral: [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

  1. Created a new SquareBracketMatcher class that handles square bracket syntax
  2. Modified the native-ollama provider to detect Magistral models and use the appropriate matcher
  3. Added comprehensive test coverage for the new matcher

Changes

  • New file: src/utils/square-bracket-matcher.ts - Handles [TAG]...[/TAG] syntax
  • Modified: src/api/providers/native-ollama.ts - Conditionally uses SquareBracketMatcher for Magistral models
  • New tests: src/utils/__tests__/square-bracket-matcher.spec.ts - 12 test cases covering all edge cases

Testing

  • ✅ All new tests pass (12/12)
  • ✅ All existing XmlMatcher tests pass (no regression)
  • ✅ Linting and type checking pass
  • ✅ Maintains backward compatibility with existing models

Screenshots

As shown in the issue, Magistral's reasoning tags are now properly recognized and hidden from the output.

Fixes #8522


Important

Adds SquareBracketMatcher for [THINK]...[/THINK] tags in Magistral models and updates NativeOllamaHandler to use it.

  • Behavior:
    • Adds SquareBracketMatcher to handle [THINK]...[/THINK] tags in square-bracket-matcher.ts.
    • Updates NativeOllamaHandler in native-ollama.ts to use SquareBracketMatcher for Magistral models.
  • Testing:
    • Adds square-bracket-matcher.spec.ts with 12 test cases for SquareBracketMatcher covering edge cases.
  • Misc:
    • No changes to existing XmlMatcher functionality.

This description was created by Ellipsis for 6de1c6e. You can customize this summary. It will automatically update as commits are pushed.

- 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
@roomote roomote bot requested review from cte, jr and mrubens as code owners October 5, 2025 23:36
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Oct 5, 2025
constructor(
readonly tagName: string,
readonly transform?: (chunks: SquareBracketMatcherResult) => Result,
readonly position = 0,
Copy link
Contributor

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.

Suggested change
readonly position = 0,

Copy link
Contributor Author

@roomote roomote bot left a 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}]`
Copy link
Contributor Author

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,
Copy link
Contributor Author

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.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Oct 5, 2025
@daniel-lxs
Copy link
Member

#8522 (comment)

@daniel-lxs daniel-lxs closed this Oct 28, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Oct 28, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Oct 28, 2025
@daniel-lxs daniel-lxs deleted the fix/magistral-think-tags-8522 branch October 28, 2025 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[BUG] Magistral [THINK]...[/THINK] tags not recognized as reasoning

4 participants