fix(agent): reasoning event source + streaming JSONDecodeError with tools - #24852
Closed
Kewe63 wants to merge 2 commits into
Closed
fix(agent): reasoning event source + streaming JSONDecodeError with tools#24852Kewe63 wants to merge 2 commits into
Kewe63 wants to merge 2 commits into
Conversation
Previously the reasoning.available event read from assistant_message.content instead of the dedicated reasoning_content or reasoning fields. This caused the event to carry final response text instead of the model's actual reasoning. Now reads from reasoning_content/reasoning first, falling back to stripped content only when no dedicated reasoning field exists. Fixes NousResearch#24518
Custom providers like LLM Gateway can fail streaming requests that include tools, returning empty/invalid responses (JSONDecodeError with 'Expecting value' on empty body). Previously this error was not detected as a streaming incompatibility, causing the request to retry streaming 3 times and fail. Now detects JSONDecodeError patterns during streaming when tools are present in the request, and disables streaming for the session so the next attempt uses the non-streaming path which succeeds. Fixes NousResearch#24523
Collaborator
This was referenced Aug 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two bug fixes in
run_agent.py:1. Fix
reasoning.availableevent source (#24518)The event was reading from
assistant_message.contentinstead of the dedicatedreasoning_contentorreasoningfields. Now reads from reasoning fields first,falling back to stripped content only when no dedicated reasoning field exists.
Also initializes
_think_text = ""to avoid unbound variable errors.2. Fix streaming
JSONDecodeErrorwhen tools are present (#24523)Custom providers like LLM Gateway can fail streaming requests that include tools,
returning empty/invalid responses. Now detects
JSONDecodeErrorpatterns anddisables streaming for the session, falling back to the non-streaming path.
Related Issues
Type of Change
Changes Made
run_agent.pyreasoning_content/reasoningfields first; init_think_text = ""run_agent.pyJSONDecodeError+ tools, disable streaming for sessionHow to Test
custom:llmgatewaywith tools → verify graceful fallback to non-streamingstreaming(34 passed),reasoning(100 passed) on WSLChecklist