Auto-GPT程序流程图
Auto-GPT介绍
https://github.com/Significant-Gravitas/Auto-GPT
Auto-GPT是一个实验性的开源应用程序,展示了GPT-4语言模型的能力。这个程序由GPT-4驱动,将LLM“思想”链接在一起,以自主地实现您设置的任何目标。作为GPT-4完全自主运行的首个示例之一,Auto-GPT推动了人工智能可能性的边界。简单来说,Auto-GPT是一种前沿的AI技术,它可以自主完成任务,让计算机变得更加智能。
Auto-GPT程序入口从cli.py开始,执行agent的全流程图,其中红色部分未暂未完全实现的功能
从目前代码来看,很多功能都还在开发中,没有官方wiki解释运行逻辑,非研发同学几乎无法使用。不过command中的第三方扩展有很大的开发空间,之后肯定会从框架内暴露出来。
约定了chatGPT返回结果的格式
def generate_prompt_string(self) -> str:"""Generate a prompt string based on the constraints, commands, resources,and performance evaluations.Returns:str: The generated prompt string."""formatted_response_format = json.dumps(self.response_format, indent=4)return (f"Constraints:\n{self._generate_numbered_list(self.constraints)}\n\n" # 约束性条件"Commands:\n"f"{self._generate_numbered_list(self.commands, item_type='command')}\n\n" # 命令f"Resources:\n{self._generate_numbered_list(self.resources)}\n\n" # 资源"Performance Evaluation:\n" f"{self._generate_numbered_list(self.performance_evaluation)}\n\n" # 性能评估"You should only respond in JSON format as described below \nResponse" # 强制ai回复json格式f" Format: \n{formatted_response_format} \nEnsure the response can be" # 要确保json可以被python json.loads解析 😓" parsed by Python json.loads")
对chatGPT的回答进行了约束
# Add constraints to the PromptGenerator object # 添加约束prompt_generator.add_constraint("~4000 word limit for short term memory. Your short term memory is short, so" # 短时记忆很短,你需要把重要信息保存在文件中" immediately save important information to files.")prompt_generator.add_constraint("If you are unsure how you previously did something or want to recall past" # 如果你不确定怎么做,试着回忆过去,想想类似的事" events, thinking about similar events will help you remember.")prompt_generator.add_constraint("No user assistance") # 没人能协助你prompt_generator.add_constraint('Exclusively use the commands listed in double quotes e.g. "command name"' # 只使用双引号中的命令,例如“命令名称”)prompt_generator.add_constraint("Use subprocesses for commands that will not terminate within a few minutes" # 对较长时间的任务,使用子进程)
对chatGPT回答的命令指令进行了格式约束
if cfg.execute_local_commands:commands.append(("Execute Shell Command, non-interactive commands only", # 你只能执行非交互式的命令"execute_shell",{"command_line": "<command_line>"},),)commands.append(("Execute Shell Command Popen, non-interactive commands only","execute_shell_popen",{"command_line": "<command_line>"},),)# Only add the download file command if the AI is allowed to execute itif cfg.allow_downloads:commands.append(("Downloads a file from the internet, and stores it locally", # 从互联网下载文件并保存在本地"download_file",{"url": "<file_url>", "file": "<saved_filename>"},),)
让chatGPT每次计算任务时都对自己的行为作自我评估
# Add performance evaluations to the PromptGenerator object # 让ai不断自我评估prompt_generator.add_performance_evaluation("Continuously review and analyze your actions to ensure you are performing to" # 不断回顾和分析你的行为,确保你的表现" the best of your abilities." # 最好的能力)prompt_generator.add_performance_evaluation("Constructively self-criticize your big-picture behavior constantly." # 不断地对自己的行为进行建设性的自我批评)prompt_generator.add_performance_evaluation("Reflect on past decisions and strategies to refine your approach." # 反思过去的决策和策略,以完善你的方法)prompt_generator.add_performance_evaluation("Every command has a cost, so be smart and efficient. Aim to complete tasks in" # 每个命令都有一个成本,所以要聪明和高效。目标是在" the least number of steps." # 最少的步骤中完成任务)
在每次给chatGPT发消息时,都会告诉ai要寻求简单的策略,没有法律风险的回答
def construct_full_prompt(self) -> str:"""Returns a prompt to the user with the class information in an organized fashion.Parameters:NoneReturns:full_prompt (str): A string containing the initial prompt for the userincluding the ai_name, ai_role and ai_goals."""# 你的决定必须独立做出,寻求用户帮助,追求简单的策略,没有法律纠纷# prompt的起始,提交给gpt的开头prompt_start = ("Your decisions must always be made independently without"" seeking user assistance. Play to your strengths as an LLM and pursue"" simple strategies with no legal complications.""")