@@ -269,7 +269,7 @@ async def generate_market_research_report(job_id: str, config: MarketResearchCon
269269 workflow = PraisonAIAgents (
270270 agents = list (agents .values ()),
271271 tasks = tasks ,
272- process = "workflow " ,
272+ process = "sequential " ,
273273 verbose = False
274274 )
275275
@@ -296,14 +296,92 @@ async def generate_market_research_report(job_id: str, config: MarketResearchCon
296296 "research_findings" : {}
297297 }
298298
299- # Extract results from each task
300- if "task_results" in results :
301- for task_name , result in results ["task_results" ].items ():
302- if result :
303- report_data ["research_findings" ][task_name ] = {
304- "content" : result .raw ,
305- "agent" : result .agent if hasattr (result , 'agent' ) else "Unknown"
306- }
299+ # Extract results from each task with comprehensive logging
300+ print (f"DEBUG: Raw results type: { type (results )} " )
301+ print (f"DEBUG: Raw results content: { results } " )
302+
303+ if isinstance (results , str ):
304+ # Sequential process returns a string result directly
305+ print ("DEBUG: Sequential process returned string result" )
306+ report_data ["research_findings" ]["synthesis_report" ] = {
307+ "content" : results ,
308+ "agent" : "Research Report Synthesizer" ,
309+ "section" : "Complete Market Research Report"
310+ }
311+ print (f"DEBUG: Added synthesis_report with content length: { len (results )} " )
312+
313+ elif isinstance (results , dict ):
314+ print (f"DEBUG: Results is dict with keys: { list (results .keys ())} " )
315+
316+ if "task_results" in results :
317+ print (f"DEBUG: Found task_results: { results ['task_results' ]} " )
318+ print (f"DEBUG: task_results type: { type (results ['task_results' ])} " )
319+
320+ for task_name , result in results ["task_results" ].items ():
321+ print (f"DEBUG: Processing task '{ task_name } ', result type: { type (result )} " )
322+ print (f"DEBUG: Result content: { result } " )
323+
324+ if result :
325+ # Try multiple ways to extract content
326+ content = None
327+ agent_name = "Unknown"
328+
329+ if hasattr (result , 'raw' ):
330+ content = result .raw
331+ print (f"DEBUG: Extracted content from result.raw" )
332+ elif hasattr (result , 'content' ):
333+ content = result .content
334+ print (f"DEBUG: Extracted content from result.content" )
335+ elif isinstance (result , str ):
336+ content = result
337+ print (f"DEBUG: Result is string, using directly" )
338+ else :
339+ content = str (result )
340+ print (f"DEBUG: Converting result to string" )
341+
342+ if hasattr (result , 'agent' ):
343+ agent_name = result .agent
344+ elif hasattr (result , 'agent_name' ):
345+ agent_name = result .agent_name
346+
347+ if content :
348+ report_data ["research_findings" ][task_name ] = {
349+ "content" : content ,
350+ "agent" : agent_name ,
351+ "section" : f"Task { task_name } "
352+ }
353+ print (f"DEBUG: Added task '{ task_name } ' with content length: { len (str (content ))} " )
354+ else :
355+ print (f"DEBUG: No content found for task '{ task_name } '" )
356+ else :
357+ print (f"DEBUG: Task '{ task_name } ' result is None or empty" )
358+ else :
359+ print ("DEBUG: No 'task_results' found in results dict" )
360+ # Try to use the whole results as content
361+ report_data ["research_findings" ]["workflow_output" ] = {
362+ "content" : str (results ),
363+ "agent" : "PraisonAI Workflow" ,
364+ "section" : "Complete Workflow Output"
365+ }
366+ print ("DEBUG: Added entire results as workflow_output" )
367+ else :
368+ print (f"DEBUG: Unexpected results type: { type (results )} " )
369+ report_data ["research_findings" ]["raw_output" ] = {
370+ "content" : str (results ),
371+ "agent" : "Unknown" ,
372+ "section" : "Raw Output"
373+ }
374+
375+ print (f"DEBUG: Final research_findings keys: { list (report_data ['research_findings' ].keys ())} " )
376+ print (f"DEBUG: Final research_findings count: { len (report_data ['research_findings' ])} " )
377+
378+ # Generate executive summary from synthesis if available
379+ if "synthesis_report" in report_data ["research_findings" ]:
380+ content = report_data ["research_findings" ]["synthesis_report" ]["content" ]
381+ # Extract first few sentences as executive summary
382+ sentences = content .split ('. ' )[:3 ]
383+ report_data ["executive_summary" ] = '. ' .join (sentences ) + '.' if sentences else "Market research analysis completed."
384+ print ("DEBUG: Generated executive summary from synthesis report" )
307385
308386 # Save report to file
309387 report_filename = f"market_research_{ job_id } .json"
0 commit comments