[PR #5695] [CLOSED] fix(agents): add reasoning parsing support for non-Ollama agent providers #5534

Closed
opened 2026-06-05 15:21:39 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Mintplex-Labs/anything-llm/pull/5695
Author: @justinchen033
Created: 5/23/2026
Status: Closed

Base: masterHead: fix/agent-reasoning-support


📝 Commits (1)

  • 158693d fix(agents): add reasoning parsing support for non-Ollama agent providers

📊 Changes

3 files changed (+162 additions, -2 deletions)

View changed files

📝 server/__tests__/utils/agents/aibitat/providers/helpers/untooled.test.js (+46 -0)
📝 server/utils/agents/aibitat/providers/helpers/tooled.js (+58 -1)
📝 server/utils/agents/aibitat/providers/helpers/untooled.js (+58 -1)

📄 Description

Pull Request Type

  • feat (New feature)
  • fix (Bug fix)
  • refactor (Code refactoring without changing behavior)
  • style (UI style changes)
  • chore (Build, CI, maintenance)
  • docs (Documentation updates)

Relevant Issues

resolves # (Resolves the issue: Non-Ollama Agent Providers Do Not Parse and Present Reasoning Content)

Description

This Pull Request adds full reasoning and thinking token extraction and parsing support (e.g., DeepSeek R1 <think> tags) to all non-Ollama agent providers in AnythingLLM.

The Problem:
During normal chats, AnythingLLM correctly intercepts, wraps, and streams reasoning content (such as reasoning_content from DeepSeek or <think> tags) so users can see the LLM's thought process. However, during Agent executions, the shared agent runners (tooled.js and untooled.js) completely discard reasoning and thinking tokens for all 30+ non-Ollama providers (DeepSeek API, LM Studio, AWS Bedrock, GiteeAI, OpenRouter, Generic OpenAI, etc.), causing the agent's reasoning steps to be lost.

The Solution:

  • Modified tooledStream and tooledComplete in tooled.js to parse reasoning tokens (choice.delta?.reasoning_content, choice.delta?.reasoningContent?.text, or choice.delta?.thinking) and wrap them in <think>...</think> tags for streaming and final responses.
  • Modified UnTooled.prototype.stream and UnTooled.prototype.complete in untooled.js to support reasoning wrapping when agents run standard chat completions or fall back to normal chat.
  • Added comprehensive unit tests inside untooled.test.js to assert and verify reasoning extraction behaviors under diverse mock inputs.

This elegantly enables reasoning support globally across all OpenAI-compatible, Bedrock, and custom agent providers in AnythingLLM.

Visuals (if applicable)

N/A (Backend logic enhancement)

Additional Information

This has been tested locally using a custom verification mock framework under Node v25 to ensure robust stream chunk tracking and transitions to tool calling or standard text.

Developer Validations

  • I ran lint checks from the root of the repo and committed changes
  • Relevant documentation has been updated (if applicable)
  • I have tested my code functionality
  • Docker build succeeds locally

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Mintplex-Labs/anything-llm/pull/5695 **Author:** [@justinchen033](https://github.com/justinchen033) **Created:** 5/23/2026 **Status:** ❌ Closed **Base:** `master` ← **Head:** `fix/agent-reasoning-support` --- ### 📝 Commits (1) - [`158693d`](https://github.com/Mintplex-Labs/anything-llm/commit/158693d1db4424ef83cf8bf2d0ab3442c4cc227f) fix(agents): add reasoning parsing support for non-Ollama agent providers ### 📊 Changes **3 files changed** (+162 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `server/__tests__/utils/agents/aibitat/providers/helpers/untooled.test.js` (+46 -0) 📝 `server/utils/agents/aibitat/providers/helpers/tooled.js` (+58 -1) 📝 `server/utils/agents/aibitat/providers/helpers/untooled.js` (+58 -1) </details> ### 📄 Description ### Pull Request Type - [ ] feat (New feature) - [x] fix (Bug fix) - [ ] refactor (Code refactoring without changing behavior) - [ ] style (UI style changes) - [ ] chore (Build, CI, maintenance) - [ ] docs (Documentation updates) ### Relevant Issues resolves # (Resolves the issue: Non-Ollama Agent Providers Do Not Parse and Present Reasoning Content) ### Description This Pull Request adds full reasoning and thinking token extraction and parsing support (e.g., DeepSeek R1 `<think>` tags) to all non-Ollama agent providers in AnythingLLM. **The Problem:** During normal chats, AnythingLLM correctly intercepts, wraps, and streams reasoning content (such as `reasoning_content` from DeepSeek or `<think>` tags) so users can see the LLM's thought process. However, during Agent executions, the shared agent runners (`tooled.js` and `untooled.js`) completely discard reasoning and thinking tokens for all 30+ non-Ollama providers (DeepSeek API, LM Studio, AWS Bedrock, GiteeAI, OpenRouter, Generic OpenAI, etc.), causing the agent's reasoning steps to be lost. **The Solution:** * Modified `tooledStream` and `tooledComplete` in `tooled.js` to parse reasoning tokens (`choice.delta?.reasoning_content`, `choice.delta?.reasoningContent?.text`, or `choice.delta?.thinking`) and wrap them in `<think>...</think>` tags for streaming and final responses. * Modified `UnTooled.prototype.stream` and `UnTooled.prototype.complete` in `untooled.js` to support reasoning wrapping when agents run standard chat completions or fall back to normal chat. * Added comprehensive unit tests inside `untooled.test.js` to assert and verify reasoning extraction behaviors under diverse mock inputs. This elegantly enables reasoning support globally across all OpenAI-compatible, Bedrock, and custom agent providers in AnythingLLM. ### Visuals (if applicable) N/A (Backend logic enhancement) ### Additional Information This has been tested locally using a custom verification mock framework under Node v25 to ensure robust stream chunk tracking and transitions to tool calling or standard text. ### Developer Validations - [x] I ran lint checks from the root of the repo and committed changes - [ ] Relevant documentation has been updated (if applicable) - [x] I have tested my code functionality - [x] Docker build succeeds locally --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 15:21:39 -04:00
yindo closed this issue 2026-06-05 15:21:39 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#5534