Skip to content

Commit 1da35db

Browse files
authored
fix(provider): only send tool_stream for Z.AI providers in streaming path (zeroclaw-labs#5806)
Squashed commits: * a639203 fix(provider): only send tool_stream for Z.AI providers in streaming path The streaming method stream_chat_with_tools unconditionally set tool_stream: true for all providers when streaming was enabled. This caused 400 Bad Request errors on non-Z.AI OpenAI-compatible endpoints (e.g. litellm proxies) that reject the unrecognized tool_stream key. The non-streaming path already correctly used tool_stream_for_tools() which gates on requires_tool_stream() (Z.AI host or name check). Apply the same guard to both streaming payload branches so the field is only serialized for Z.AI providers. Related: zeroclaw-labs#2901
1 parent 9328946 commit 1da35db

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

crates/zeroclaw-providers/src/compatible.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,7 +2195,11 @@ impl Provider for OpenAiCompatibleProvider {
21952195
messages: Self::convert_messages_for_native(&effective_messages, !merge),
21962196
temperature,
21972197
reasoning_effort: self.reasoning_effort.clone(),
2198-
tool_stream: if options.enabled { Some(true) } else { None },
2198+
tool_stream: if options.enabled {
2199+
self.tool_stream_for_tools(true)
2200+
} else {
2201+
None
2202+
},
21992203
stream: Some(options.enabled),
22002204
tools: tools.clone(),
22012205
tool_choice: tools.as_ref().map(|_| "auto".to_string()),
@@ -2215,7 +2219,11 @@ impl Provider for OpenAiCompatibleProvider {
22152219
messages,
22162220
temperature,
22172221
reasoning_effort: self.reasoning_effort.clone(),
2218-
tool_stream: if options.enabled { Some(true) } else { None },
2222+
tool_stream: if options.enabled {
2223+
self.tool_stream_for_tools(false)
2224+
} else {
2225+
None
2226+
},
22192227
stream: Some(options.enabled),
22202228
tools: None,
22212229
tool_choice: None,
@@ -3597,6 +3605,14 @@ mod tests {
35973605
assert!(!json.contains("\"tool_stream\""));
35983606
}
35993607

3608+
#[test]
3609+
fn non_zai_provider_omits_tool_stream_regardless_of_streaming() {
3610+
let provider = make_provider("custom", "https://proxy.example.com/v1", None);
3611+
// tool_stream_for_tools should return None for non-Z.AI providers
3612+
assert_eq!(provider.tool_stream_for_tools(true), None);
3613+
assert_eq!(provider.tool_stream_for_tools(false), None);
3614+
}
3615+
36003616
#[test]
36013617
fn z_ai_host_enables_tool_stream_for_custom_profiles() {
36023618
let provider = make_provider("custom", "https://api.z.ai/api/coding/paas/v4", None);

0 commit comments

Comments
 (0)