fix(agent): enable tool_stream for zai chat transport - #14619
Open
Srnki wants to merge 1 commit into
Open
Conversation
teknium1
reviewed
Jul 12, 2026
teknium1
left a comment
Contributor
There was a problem hiding this comment.
Thanks for isolating the Z.AI tool-streaming behavior. The automatic default is still absent on current main, but this patch now lands on a bypassed path.
Problems
- Registered Z.AI requests resolve through
agent/chat_completion_helpers.py:849-888withprovider_profile;agent/transports/chat_completions.py:316-321returns through_build_kwargs_from_profilebefore the legacyextra_bodyblock changed here.plugins/model-providers/zai/__init__.py:88-108currently has notool_streamemission. run_agent.py:5328-5331is now a forwarder after extraction commit4b25619bc4770396faf206429ddc180ad02231a9; the request-builder body is inagent/chat_completion_helpers.py.- The new test omits
provider_profile, so it validates only the legacy fallback rather than the direct Z.AI runtime route.
Suggested changes
- Move the tools-only Z.AI/base-URL gate into the current profile-aware assembly, covering both
zaiand custom Z.AI endpoints. - Preserve override precedence by applying the default before
request_overrides.extra_bodymerges atagent/transports/chat_completions.py:601-608, then add profile-path regression coverage.
Automated hermes-sweeper review.
| ) | ||
|
|
||
| if _is_zai_endpoint and tools: | ||
| extra_body.setdefault("tool_stream", True) |
Contributor
There was a problem hiding this comment.
This branch is now below the provider_profile early return on current main (agent/transports/chat_completions.py:316-321), so direct provider="zai" requests never reach it. Please place the default in the profile-aware assembly as well, while retaining request-override precedence.
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.
What does this PR do?
This PR enables
tool_stream=truefor Z.AI / BigModel chat-completions requests in the current transport-based code path.GLM models on Z.AI can buffer large tool-call arguments and remain silent long enough to hit the provider's idle timeout. Hermes already has an open fix for the older
_build_api_kwargspath, but the current codebase now assemblesextra_bodyinsideagent/transports/chat_completions.py.This change ports the same behavior to the current transport path by detecting Z.AI endpoints from
provider/base_urland enablingtool_streamonly when tools are present.Related Issue
Fixes #
Type of Change
Changes Made
providerandbase_urlfromrun_agent.pyintoChatCompletionsTransport.build_kwargs()agent/transports/chat_completions.pyto setextra_body["tool_stream"] = Truewhen:provider == "zai", orbase_urlcontainsz.aiorbigmodel.cnsetdefault()so explicit overrides still wintests/agent/transports/test_chat_completions.pyfor:tool_streamHow to Test
Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/AScreenshots / Logs
Manual validation against Z.AI succeeded with a real Hermes tool-call run:
https://api.z.ai/api/coding/paas/v4/chat/completionsTOOL_OKextra_body.tool_stream = trueThere is already an open PR for the older code path: #12758. This PR applies the same fix to the current transport-based implementation.
Note: the full repository test suite currently has unrelated pre-existing failures, so this PR adds targeted regression coverage for the transport path changed here.