Skip to content

fix(agent): reasoning event source + streaming JSONDecodeError with tools - #24852

Closed
Kewe63 wants to merge 2 commits into
NousResearch:mainfrom
Kewe63:fix/run-agent-bugs
Closed

fix(agent): reasoning event source + streaming JSONDecodeError with tools#24852
Kewe63 wants to merge 2 commits into
NousResearch:mainfrom
Kewe63:fix/run-agent-bugs

Conversation

@Kewe63

@Kewe63 Kewe63 commented May 13, 2026

Copy link
Copy Markdown
Contributor

Two bug fixes in run_agent.py:

1. Fix reasoning.available event source (#24518)

The event was reading from assistant_message.content instead of the dedicated
reasoning_content or reasoning fields. 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 JSONDecodeError when tools are present (#24523)

Custom providers like LLM Gateway can fail streaming requests that include tools,
returning empty/invalid responses. Now detects JSONDecodeError patterns and
disables streaming for the session, falling back to the non-streaming path.


Related Issues


Type of Change

  • 🐛 Bug fix

Changes Made

File Line Change
run_agent.py ~L14581 Read from reasoning_content/reasoning fields first; init _think_text = ""
run_agent.py ~L8501 Detect JSONDecodeError + tools, disable streaming for session

How to Test

  1. api_server: reasoning.available event carries final response text instead of reasoning_content #24518 — Use a reasoning model → verify the event carries reasoning content, not the response text
  2. [Bug]: custom:llmgateway tool calls fail when streamed [ROOT CAUSE FOUND - upstream openai-python#2722] #24523 — Use custom:llmgateway with tools → verify graceful fallback to non-streaming
  3. Testsstreaming (34 passed), reasoning (100 passed) on WSL

Checklist

  • Conventional Commits
  • Tests pass
  • Tested on WSL (Linux)

Kewe63 added 2 commits May 13, 2026 08:55
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
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists labels May 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #24532 — both fix the JSONDecodeError streaming fallback for custom providers (closes #24523). The reasoning event source fix (#24518) was separately addressed by closed #24535. See also #24572 (another dup of #24532).

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

2 participants