Skip to content

Commit 488a659

Browse files
committed
refactor: migrate workflow process to sequential and enhance result handling with debug logging
1 parent b012c91 commit 488a659

File tree

2 files changed

+117
-42
lines changed

2 files changed

+117
-42
lines changed

examples/python/api/secondary-market-research-api.py

Lines changed: 87 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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"

src/praisonai-agents/test.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
1-
import os
2-
3-
# Set OpenAI API configuration BEFORE importing praisonaiagents
4-
# os.environ["OPENAI_API_BASE"] = "http://localhost:1234/v1"
5-
# os.environ["OPENAI_API_KEY"] = "not-needed"
6-
7-
# Now import after setting the environment
8-
from praisonaiagents import Agent, MCP
1+
from praisonaiagents import Agent, Task, PraisonAIAgents
2+
from praisonaiagents.tools import (
3+
read_file, write_file, list_files, get_file_info,
4+
copy_file, move_file, delete_file
5+
)
96

10-
# Paths to python and the weather server script
11-
python_path = os.getenv("PYTHON_PATH", "python")
12-
server_path = os.getenv("WEATHER_SERVER_PATH", "weather_server.py")
7+
# Get user input
8+
d = input("Demande: ")
139

14-
# Create the agent with Ollama
15-
weather_agent = Agent(
16-
name="Weather Assistant",
17-
role="Weather assistant",
18-
goal="Provide accurate and timely weather information for various cities",
19-
instructions="""
20-
You are a helpful weather assistant that can provide current weather information,
21-
forecasts, and weather comparisons for different cities. Use the available weather tools to answer
22-
user questions about weather conditions. You can:
10+
# Create file manager agent
11+
file_manager_agent = Agent(
12+
name="FileManager",
13+
tools=[read_file, write_file, list_files, get_file_info,
14+
copy_file, move_file, delete_file],
15+
llm={
16+
"model": "ollama/llama3.2",
17+
"base_url": "http://localhost:11434" # Ollama default
18+
}
19+
)
2320

24-
- Get current weather for cities
25-
- Get hourly forecasts
26-
- Compare weather between two cities
27-
- Use both mock data and real API data (when API key is provided)
28-
- Set use_real_api True to use real API data all the time
21+
# Dynamically create a task based on input
22+
file_task = Task(
23+
name="Q",
24+
description=f"faire '{d}'.",
25+
expected_output=f"'{d}' bien fait.",
26+
agent=file_manager_agent
27+
)
2928

30-
Always use the appropriate weather tools when users ask about weather information.
31-
""",
32-
llm="ollama/llama3.2", # Using Ollama with llama3.2
33-
tools=MCP(f"{python_path} {server_path}"),
34-
verbose=True
29+
# Run agent with the task
30+
agents = PraisonAIAgents(
31+
agents=[file_manager_agent],
32+
tasks=[file_task],
33+
process="sequential"
3534
)
3635

37-
# Optional: run a sample task
38-
response = weather_agent.start("What's the weather in London?")
39-
print(response)
36+
agents.start()

0 commit comments

Comments
 (0)