1
0

test_simple_agent.py 768 B

1234567891011121314151617181920212223242526272829
  1. # test_simple_agent.py
  2. from dotenv import load_dotenv
  3. from hello_agents import HelloAgentsLLM
  4. from my_simple_agent import MySimpleAgent
  5. # 加载环境变量
  6. load_dotenv()
  7. # 创建LLM实例
  8. llm = HelloAgentsLLM()
  9. # 创建自定义SimpleAgent
  10. agent = MySimpleAgent(
  11. name="我的简单助手",
  12. llm=llm,
  13. system_prompt="你是一个友好的AI助手,请用简洁明了的方式回答问题。"
  14. )
  15. # 测试标准调用
  16. response1 = agent.run("你好,请介绍一下自己")
  17. print(f"标准响应: {response1}")
  18. # 测试流式调用
  19. print("\n流式响应:")
  20. for chunk in agent.stream_run("请解释什么是人工智能"):
  21. pass # 内容已在stream_run中实时打印
  22. # 查看对话历史
  23. print(f"\n对话历史: {len(agent.get_history())} 条消息")