Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/praisonai-agents/praisonaiagents/agent/chat_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ def _process_stream_response(self, messages, temperature, start_time, formatted_
emit_events=True
)

def _chat_completion(self, messages, temperature=1.0, tools=None, stream=True, reasoning_steps=False, task_name=None, task_description=None, task_id=None, response_format=None, _retry_depth=0):
def _chat_completion(self, messages, temperature=1.0, tools=None, stream=False, reasoning_steps=False, task_name=None, task_description=None, task_id=None, response_format=None, _retry_depth=0):
start_time = time.time()

# --- Context compaction (opt-in via ExecutionConfig.context_compaction) ---
Expand Down Expand Up @@ -774,7 +774,7 @@ def _execute_unified_chat_completion(
messages,
temperature=1.0,
tools=None,
stream=True,
stream=False,
reasoning_steps=False,
task_name=None,
task_description=None,
Expand Down
51 changes: 51 additions & 0 deletions test_multiagent_fix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env python3
"""Test script to reproduce and verify fix for multi-agent streaming issue #1733"""

import sys
import os

# Add the praisonaiagents package to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'src', 'praisonai-agents'))

print("Testing multi-agent functionality with the fix...")

try:
from praisonaiagents import Agent, Agents

research_agent = Agent(instructions="Research about AI")
summarise_agent = Agent(instructions="Summarise research agent's findings")
agents = Agents(agents=[research_agent, summarise_agent])

print("✓ Successfully created agents")

# Test that our fix worked: the sync methods should not use streaming by default
# Check the method signatures in chat_mixin.py
import inspect
from praisonaiagents.agent.chat_mixin import ChatMixin

# Check _chat_completion method
chat_completion_sig = inspect.signature(ChatMixin._chat_completion)
stream_param = chat_completion_sig.parameters.get('stream')
if stream_param and stream_param.default == False:
print("✓ _chat_completion method has stream=False as default")
else:
print(f"✗ _chat_completion method stream default is: {stream_param.default}")

# Check _execute_unified_chat_completion method
unified_chat_sig = inspect.signature(ChatMixin._execute_unified_chat_completion)
unified_stream_param = unified_chat_sig.parameters.get('stream')
if unified_stream_param and unified_stream_param.default == False:
print("✓ _execute_unified_chat_completion method has stream=False as default")
else:
print(f"✗ _execute_unified_chat_completion method stream default is: {unified_stream_param.default}")

print("✓ Fix validation completed - sync methods now default to stream=False")
print("✓ This should resolve the 'Streaming is not supported in sync OpenAIAdapter' error")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Validation script does not fail on regression.

This script prints failure markers but still exits successfully, so it can report “All tests passed!” even when defaults are wrong.

Suggested fix
@@
-    if stream_param and stream_param.default == False:
+    failures = []
+
+    if stream_param is not None and stream_param.default is False:
         print("✓ _chat_completion method has stream=False as default")
     else:
-        print(f"✗ _chat_completion method stream default is: {stream_param.default}")
+        actual = getattr(stream_param, "default", "<missing parameter>")
+        failures.append(f"_chat_completion stream default is {actual!r} (expected False)")
@@
-    if unified_stream_param and unified_stream_param.default == False:
+    if unified_stream_param is not None and unified_stream_param.default is False:
         print("✓ _execute_unified_chat_completion method has stream=False as default")
     else:
-        print(f"✗ _execute_unified_chat_completion method stream default is: {unified_stream_param.default}")
+        actual = getattr(unified_stream_param, "default", "<missing parameter>")
+        failures.append(
+            f"_execute_unified_chat_completion stream default is {actual!r} (expected False)"
+        )
+
+    if failures:
+        for failure in failures:
+            print(f"✗ {failure}")
+        sys.exit(1)
@@
-print("✓ All tests passed!")
+print("✓ All tests passed!")

Also applies to: 51-51

🧰 Tools
🪛 Ruff (0.15.13)

[error] 29-29: Avoid equality comparisons to False; use not stream_param.default: for false checks

Replace with not stream_param.default

(E712)


[error] 37-37: Avoid equality comparisons to False; use not unified_stream_param.default: for false checks

Replace with not unified_stream_param.default

(E712)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test_multiagent_fix.py` around lines 29 - 43, The validation script currently
prints pass/fail messages but always exits zero; update the checks for
_chat_completion and ChatMixin._execute_unified_chat_completion so that when
either stream default is not False the script records failure and exits with a
non-zero status (e.g., call sys.exit(1) or set a failure flag and exit after
checks). Locate the inspection logic around symbols _chat_completion and
ChatMixin._execute_unified_chat_completion in test_multiagent_fix.py (also the
similar check around line 51) and ensure any failure path triggers a non-zero
exit so CI will fail on regressions.


except Exception as e:
print(f"✗ Error occurred during validation: {e}")
import traceback
traceback.print_exc()
sys.exit(1)

print("✓ All tests passed!")
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
Loading