test_reflection_agent.py 854 B

1234567891011121314151617181920212223242526
  1. # test_reflection_agent.py
  2. from dotenv import load_dotenv
  3. from hello_agents import HelloAgentsLLM
  4. from my_reflection_agent import MyReflectionAgent
  5. load_dotenv()
  6. llm = HelloAgentsLLM()
  7. # 使用默认通用提示词
  8. general_agent = MyReflectionAgent(name="我的反思助手", llm=llm)
  9. # 使用自定义代码生成提示词(类似第四章)
  10. code_prompts = {
  11. "initial": "你是Python专家,请编写函数:{task}",
  12. "reflect": "请审查代码的算法效率:\n任务:{task}\n代码:{content}",
  13. "refine": "请根据反馈优化代码:\n任务:{task}\n反馈:{feedback}"
  14. }
  15. code_agent = MyReflectionAgent(
  16. name="我的代码生成助手",
  17. llm=llm,
  18. custom_prompts=code_prompts
  19. )
  20. # 测试使用
  21. result = general_agent.run("写一篇关于人工智能发展历程的简短文章")
  22. print(f"最终结果: {result}")