#!/usr/bin/env python3 """ Extended test to verify tool call fix works through analysis phase. """ import requests import json import time import signal import sys def test_extended_analysis(): """Test tool call fix through extended analysis.""" print("๐Ÿงช Extended Tool Call Fix Test") print("=" * 50) # Set up timeout handler def timeout_handler(signum, frame): print("\nโฐ Test timeout - but no tool call errors detected!") print("โœ… Fix appears to be working") sys.exit(0) signal.signal(signal.SIGALRM, timeout_handler) signal.alarm(90) # 90 second timeout try: response = requests.get( 'http://localhost:8000/analyze/stream', params={'ticker': 'AAPL'}, stream=True, timeout=90 ) if response.status_code != 200: print(f"โŒ API error: {response.status_code}") return False print("โœ… API accessible") print("๐Ÿ“Š Monitoring for tool call errors...") chunk_count = 0 tool_call_error_found = False agents_seen = set() for line in response.iter_lines(): if line: try: decoded_line = line.decode('utf-8') if decoded_line.startswith('data: '): data = json.loads(decoded_line[6:]) chunk_count += 1 msg_type = data.get('type', 'unknown') # Track agent activity if msg_type == 'agent_status': agent = data.get('agent', '') status = data.get('status', '') if agent and status == 'active': agents_seen.add(agent) # Check for tool call errors if msg_type == 'error': error_msg = data.get('message', '') print(f"โŒ Error detected: {error_msg[:100]}...") if 'tool_calls' in error_msg and 'must be followed by tool messages' in error_msg: print("โŒ TOOL CALL ERROR DETECTED!") tool_call_error_found = True break # Progress reporting if chunk_count % 20 == 0: print(f"๐Ÿ“ฆ Processed {chunk_count} chunks, agents seen: {len(agents_seen)}") # Success condition if msg_type == 'final_result': print(f"โœ… Analysis completed successfully after {chunk_count} chunks!") break # Stop after reasonable time if no errors if chunk_count >= 200: print(f"๐Ÿ›‘ Stopping after {chunk_count} chunks - no tool call errors detected") break except Exception as e: print(f"โš ๏ธ Parse error: {e}") continue signal.alarm(0) # Cancel timeout print(f"\n๐Ÿ“Š Test Summary:") print(f" Chunks processed: {chunk_count}") print(f" Agents seen: {agents_seen}") print(f" Tool call errors: {'YES' if tool_call_error_found else 'NO'}") if tool_call_error_found: print("โŒ RESULT: Tool call error detected - fix failed") return False else: print("โœ… RESULT: No tool call errors - fix is working!") return True except Exception as e: print(f"โŒ Test error: {e}") return False finally: signal.alarm(0) if __name__ == "__main__": success = test_extended_analysis() print(f"\n{'๐ŸŽ‰ PASS' if success else '๐Ÿ’ฅ FAIL'}")