Skip to content

Commit 80dc147

Browse files
Merge pull request #1045 from MervinPraison/claude/pr-1042-20250722-2118
fix: correct display_generating logic to only show when stream=False AND verbose=True
2 parents 847cafe + c6f0e20 commit 80dc147

3 files changed

Lines changed: 27 additions & 36 deletions

File tree

src/praisonai-agents/praisonaiagents/agent/agent.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ def _process_stream_response(self, messages, temperature, start_time, formatted_
10701070
tools=formatted_tools,
10711071
start_time=start_time,
10721072
console=self.console,
1073-
display_fn=display_generating,
1073+
display_fn=display_generating if (not stream and self.verbose) else None, # stream is True in this context
10741074
reasoning_steps=reasoning_steps
10751075
)
10761076

@@ -1110,7 +1110,7 @@ def _chat_completion(self, messages, temperature=0.2, tools=None, stream=True, r
11101110
)
11111111
else:
11121112
# Non-streaming with custom LLM - add display functionality for verbose mode
1113-
if (stream or self.verbose) and self.console:
1113+
if (not stream and self.verbose) and self.console:
11141114
# Show "Generating..." display for verbose mode like OpenAI path
11151115
with Live(
11161116
display_generating("", start_time),
@@ -1169,7 +1169,7 @@ def _chat_completion(self, messages, temperature=0.2, tools=None, stream=True, r
11691169
execute_tool_fn=self.execute_tool,
11701170
stream=stream,
11711171
console=self.console if (self.verbose or stream) else None,
1172-
display_fn=display_generating if (stream or self.verbose) else None,
1172+
display_fn=display_generating if (not stream and self.verbose) else None,
11731173
reasoning_steps=reasoning_steps,
11741174
verbose=self.verbose,
11751175
max_iterations=10
@@ -1921,25 +1921,16 @@ async def _achat_completion(self, response, tools, reasoning_steps=False):
19211921
chunks = []
19221922
start_time = time.time()
19231923

1924-
with Live(
1925-
display_generating("", start_time),
1926-
console=self.console,
1927-
refresh_per_second=4,
1928-
transient=True,
1929-
vertical_overflow="ellipsis",
1930-
auto_refresh=True
1931-
) as live:
1932-
async for chunk in final_response:
1933-
chunks.append(chunk)
1934-
if chunk.choices[0].delta.content:
1935-
full_response_text += chunk.choices[0].delta.content
1936-
live.update(display_generating(full_response_text, start_time))
1937-
1938-
if reasoning_steps and hasattr(chunk.choices[0].delta, "reasoning_content"):
1939-
rc = chunk.choices[0].delta.reasoning_content
1940-
if rc:
1941-
reasoning_content += rc
1942-
live.update(display_generating(f"{full_response_text}\n[Reasoning: {reasoning_content}]", start_time))
1924+
# Process stream without display_generating since streaming is active
1925+
async for chunk in final_response:
1926+
chunks.append(chunk)
1927+
if chunk.choices[0].delta.content:
1928+
full_response_text += chunk.choices[0].delta.content
1929+
1930+
if reasoning_steps and hasattr(chunk.choices[0].delta, "reasoning_content"):
1931+
rc = chunk.choices[0].delta.reasoning_content
1932+
if rc:
1933+
reasoning_content += rc
19431934

19441935
self.console.print()
19451936

test_comprehensive_display_fix.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def test_display_logic():
1818
test_cases = [
1919
{"stream": False, "verbose": False, "expected": False, "description": "No display (stream=False, verbose=False)"},
2020
{"stream": False, "verbose": True, "expected": True, "description": "Display in verbose mode (stream=False, verbose=True) - MAIN FIX"},
21-
{"stream": True, "verbose": False, "expected": True, "description": "Display in stream mode (stream=True, verbose=False)"},
22-
{"stream": True, "verbose": True, "expected": True, "description": "Display in both modes (stream=True, verbose=True)"},
21+
{"stream": True, "verbose": False, "expected": False, "description": "No display when streaming (stream=True, verbose=False)"},
22+
{"stream": True, "verbose": True, "expected": False, "description": "No display when streaming (stream=True, verbose=True)"},
2323
]
2424

2525
print(f"{'Description':<55} {'Stream':<8} {'Verbose':<8} {'Expected':<8} {'Result':<8} {'Status'}")
@@ -28,7 +28,7 @@ def test_display_logic():
2828
all_passed = True
2929
for case in test_cases:
3030
# Test the actual logic used in the fix
31-
result = (case["stream"] or case["verbose"])
31+
result = (not case["stream"] and case["verbose"])
3232
expected = case["expected"]
3333
status = "✅ PASS" if result == expected else "❌ FAIL"
3434

@@ -61,11 +61,11 @@ def test_agent_paths():
6161
content = f.read()
6262

6363
# Check for OpenAI path fix
64-
openai_fix = "display_fn=display_generating if (stream or self.verbose) else None"
64+
openai_fix = "display_fn=display_generating if (not stream and self.verbose) else None"
6565
has_openai_fix = openai_fix in content
6666

6767
# Check for custom LLM path fix
68-
custom_llm_fix = "if (stream or self.verbose) and self.console:"
68+
custom_llm_fix = "if (not stream and self.verbose) and self.console:"
6969
has_custom_fix = custom_llm_fix in content
7070

7171
print(f"OpenAI path fix present: {'✅ YES' if has_openai_fix else '❌ NO'}")
@@ -84,14 +84,14 @@ def test_backward_compatibility():
8484

8585
# Test cases that should maintain existing behavior
8686
scenarios = [
87-
{"name": "Default streaming behavior", "stream": True, "verbose": True, "should_display": True},
87+
{"name": "Default streaming behavior", "stream": True, "verbose": True, "should_display": False},
8888
{"name": "Non-verbose non-streaming", "stream": False, "verbose": False, "should_display": False},
89-
{"name": "Streaming with verbose off", "stream": True, "verbose": False, "should_display": True},
89+
{"name": "Streaming with verbose off", "stream": True, "verbose": False, "should_display": False},
9090
]
9191

9292
all_compat = True
9393
for scenario in scenarios:
94-
result = (scenario["stream"] or scenario["verbose"])
94+
result = (not scenario["stream"] and scenario["verbose"])
9595
expected = scenario["should_display"]
9696
status = "✅ COMPATIBLE" if result == expected else "❌ INCOMPATIBLE"
9797

test_logic.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ def original_logic(stream, verbose):
88

99
# Fixed logic
1010
def fixed_logic(stream, verbose):
11-
return (stream or verbose)
11+
return (not stream and verbose)
1212

1313
print("=== Testing display_generating logic fix ===")
1414

1515
# Test cases
1616
test_cases = [
1717
{"stream": False, "verbose": False, "expected_display": False, "description": "No verbose, no stream"},
1818
{"stream": False, "verbose": True, "expected_display": True, "description": "Verbose but no stream (user's case)"},
19-
{"stream": True, "verbose": False, "expected_display": True, "description": "Stream but no verbose"},
20-
{"stream": True, "verbose": True, "expected_display": True, "description": "Both stream and verbose"},
19+
{"stream": True, "verbose": False, "expected_display": False, "description": "Stream but no verbose (no display when streaming)"},
20+
{"stream": True, "verbose": True, "expected_display": False, "description": "Both stream and verbose (no display when streaming)"},
2121
]
2222

2323
print(f"{'Description':<35} {'Stream':<8} {'Verbose':<8} {'Original':<10} {'Fixed':<8} {'Expected':<8} {'Status'}")
@@ -39,10 +39,10 @@ def fixed_logic(stream, verbose):
3939
print("-" * 80)
4040
if all_passed:
4141
print("✅ All tests PASSED! The fix should work correctly.")
42-
print("✅ display_generating will now be called when verbose=True, even with stream=False")
42+
print("✅ display_generating will now ONLY be called when stream=False AND verbose=True")
4343
else:
4444
print("❌ Some tests FAILED!")
4545

4646
print("\n=== Key Fix ===")
47-
print("Before: display_fn=display_generating if stream else None")
48-
print("After: display_fn=display_generating if (stream or verbose) else None")
47+
print("Before: display_fn=display_generating if (stream or verbose) else None")
48+
print("After: display_fn=display_generating if (not stream and verbose) else None")

0 commit comments

Comments
 (0)