rewoo
Module Contents
Classes
A wrapper of ReWOO prompt which manages the response from LLM and |
|
An implementation of ReWOO (https://arxiv.org/abs/2305.18323) |
Attributes
- lagent.agents.rewoo.PLANNER_PROMPT_CN = Multiline-String
Show Value
"""你是一个任务分解器, 你需要将用户的问题拆分成多个简单的子任务。 请拆分出多个子任务项,从而能够得到充分的信息以解决问题, 返回格式如下: ``` Plan: 当前子任务要解决的问题 #E[id] = 工具名称[工具参数] Plan: 当前子任务要解决的问题 #E[id] = 工具名称[工具参数] ``` 其中 1. #E[id] 用于存储Plan id的执行结果, 可被用作占位符。 2. 每个 #E[id] 所执行的内容应与当前Plan解决的问题严格对应。 3. 工具参数可以是正常输入text, 或是 #E[依赖的索引], 或是两者都可以。 4. 工具名称必须从一下工具中选择: {tool_description} 注意: 每个Plan后有且仅能跟随一个#E。 开始!"""
- lagent.agents.rewoo.WORKER_PROMPT_CN = Multiline-String
Show Value
""" 想法: {thought} 回答: {action_resp} """
- lagent.agents.rewoo.SOLVER_PROMPT_CN = Multiline-String
Show Value
"""解决接下来的任务或者问题。为了帮助你,我们提供了一些相关的计划 和相应的解答。注意其中一些信息可能存在噪声,因此你需要谨慎的使用它们。 {question} {worker_log} 现在开始回答这个任务或者问题。请直接回答这个问题, 不要包含其他不需要的文字。{question} """
- lagent.agents.rewoo.REFORMAT_PROMPT_CN = '回答格式错误: {err_msg}。 请重新回答:\n'
- lagent.agents.rewoo.PLANNER_PROMPT_EN = Multiline-String
Show Value
"""You are a task decomposer, and you need to break down the user's problem into multiple simple subtasks. Please split out multiple subtask items so that sufficient information can be obtained to solve the problem. The return format is as follows: ``` Plan: the problem to be solved by the current subtask #E[id] = tool_name[tool_inputs] Plan: the problem to be solved by the current subtask #E[id] = tool_name[tool_inputs] ``` 1. #E[id] is used to store the execution result of the plan id and can be used as a placeholder. 2. The content implemented by each #E[id] should strictly correspond to the problem currently planned to be solved. 3. Tool parameters can be entered as normal text, or #E[dependency_id], or both. 4. The tool name must be selected from the tool: {tool_description}. Note: Each plan should be followed by only one #E. Start! """
- lagent.agents.rewoo.WORKER_PROMPT_EN = Multiline-String
Show Value
""" Thought: {thought} Response: {action_resp} """
- lagent.agents.rewoo.SOLVER_PROMPT_EN = Multiline-String
Show Value
"""Solve the following task or problem. To assist you, we provide some plans and corresponding evidences that might be helpful. Notice that some of these information contain noise so you should trust them with caution. {question} {worker_log} Now begin to solve the task or problem. Respond with the answer directly with no extra words.{question} """
- lagent.agents.rewoo.REFORMAT_PROMPT_EN = 'Response Format Error: {err_msg}. Please reply again:\n'
- class lagent.agents.rewoo.ReWOOProtocol(planner_prompt=PLANNER_PROMPT_EN, worker_prompt=WORKER_PROMPT_EN, solver_prompt=SOLVER_PROMPT_EN, reformat_prompt=REFORMAT_PROMPT_EN)
A wrapper of ReWOO prompt which manages the response from LLM and generate desired prompts in a ReWOO format.
- Parameters:
planner_prompt (str) – prompt template for planner.
worker_prompt (str) – prompt template for workers/actions.
solver_prompt (str) – prompt template for solver.
reformat_prompt (str) – prompt template to regenerate response for LLM.
- format_planner(chat_history, inner_step, action_executor, reformat_request='')
Generate the planner prompt required by ReWOO.
- Parameters:
chat_history (List[Dict]) – The history log in previous runs.
inner_step (List[Dict]) – The log in the current run.
action_executor (ActionExecutor) – the action manager to execute actions.
reformat_request (str) – the error feedback if the LLM fails to generate required format for planner.
- Returns:
ReWOO format prompt for planner.
- Return type:
List[Dict]
- parse_worker(message)
Parse the LLM generated planner response and convert it into the worker format.
- Parameters:
message (str) – The response from LLM with ReWOO planner format.
- Returns:
- the return value is a tuple contains:
- thought_list (List(str)): contain LLM thoughts of the user
request.
action_list (List(str)): contain actions scheduled by LLM.
- action_input_list (List(str)): contain the required action
input for above actions.
- Return type:
tuple
- format_solver(question, thought_list, action_return_list)
Generate the prompt for solver in a ReWOO format.
- Parameters:
question (str) – The user request in the current run.
thought_list (List[str]) – thoughts generated from LLM for each action.
action_return_list (List[ActionReturn]) – action returns from workers.
- Returns:
- the return value is a tuple contains:
- solver_prompt (str): the generated prompt for solver
in a ReWOO format.
- worker_log (str): contain action responses from workers.
Used for inner log.
- Return type:
tuple
- class lagent.agents.rewoo.ReWOO(llm, action_executor, protocol=ReWOOProtocol(), max_turn=2)
Bases:
lagent.agents.base_agent.BaseAgentAn implementation of ReWOO (https://arxiv.org/abs/2305.18323)
- Parameters:
llm (BaseModel or BaseAPIModel) – a LLM service which can chat and act as planner / solver.
action_executor (ActionExecutor) – an action executor to manage all actions and their response.
protocol (ReWOOProtocol) – a wrapper to generate prompt and parse the response from LLM / actions.
max_turn (int) – the maximum number of trails for LLM to generate plans that can be successfully parsed by ReWOO protocol.
- chat(message, **kwargs)
- Parameters:
message (Union[str, dict, List[dict]]) –
- Return type: