import os import json from hello_agents import HelloAgentsLLM, SimpleAgent from agents.agent_prompts import REPORT_AGENT_PROMPT if __name__ == "__main__": llm = HelloAgentsLLM() report_agent = SimpleAgent( name="ReportAgent", system_prompt=REPORT_AGENT_PROMPT, llm=llm, enable_tool_calling=False ) task_result = [ { 'task': '分析不同年龄段用户的偏好', 'result': { 'text': '各年龄段平均消费金额相近,均在58-61之间。商品类别偏好显示,所有年龄段均最偏好服装(Clothing),占比约44%-46%;其次是配饰(Accessories),占比约29%-34%;鞋类(Footwear)和外套(Outerwear)偏好相对较低。其中,20-30岁用户更偏好配饰,40-50岁用户更偏好鞋类,青少年(<20)和老年人(60+)对外套的偏好相对较高。', 'visualization_url': ['figures/age_group_distribution.png', 'figures/average_spending_by_age_group.png', 'figures/category_preference_by_age_group.png'] } } ] print(f"\n任务结果: {task_result}") final_result = report_agent.run(json.dumps(task_result, ensure_ascii=False)) # 清理报告内容,确保以"# 执行摘要"开头 if "# 执行摘要" in final_result: # 找到"# 执行摘要"的位置 start_idx = final_result.find("# 执行摘要") final_result = final_result[start_idx:] print(f"\n最终分析报告: \n{final_result}") # 保存报告到文件 os.makedirs("out", exist_ok=True) with open("out/analysis_report.md", "w", encoding="utf-8") as f: f.write(final_result)