You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# test_reflection_agent.py
from dotenv import load_dotenv
from hello_agents import HelloAgentsLLM
from my_reflection_agent import MyReflectionAgent
load_dotenv ( )
llm = HelloAgentsLLM ( )
# 使用默认通用提示词
general_agent = MyReflectionAgent ( name = " 我的反思助手 " , llm = llm )
# 使用自定义代码生成提示词(类似第四章)
code_prompts = {
" initial " : " 你是Python专家, 请编写函数: {task} " ,
" reflect " : " 请审查代码的算法效率: \n 任务: {task} \n 代码: {content} " ,
" refine " : " 请根据反馈优化代码: \n 任务: {task} \n 反馈: {feedback} "
}
code_agent = MyReflectionAgent (
name = " 我的代码生成助手 " ,
llm = llm ,
custom_prompts = code_prompts
)
# 测试使用
result = general_agent . run ( " 写一篇关于人工智能发展历程的简短文章 " )
print ( f " 最终结果: { result } " )