ReAct 是一种 LLM 提示和结果处理方法,结合了推理、行动计划和知识源整合,使 LLM 超越其语言模型,并在预测中使用来自现实世界的信息。 ReAct 是推理和行动的结合。
介绍 ReAct 的论文表明它比思维链提示更好。与后者不同的是,ReAct 不会过多地幻化事实。然而,为了获得最佳结果,论文建议将 ReAct 和思维链提示与自我一致性检查结合起来。

- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
-
- you have access to the following tools:
- [{tool_name_and_description}]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [{tool_names}]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeat N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: {question}
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>
- You are an assistant to give people the answer of questions.
- Human may provide new question to you with a description and you should use tools to get the answer, rather than directly reply from the description.
-
- You have access to the following tools:
-
- > Search: Search for a term in Wikipedia and return the first sentence. The input to this tool should be a string to search.
- > Lookup: Lookup a term in the Wikipedia article and return sentence which describes about a term. The input to this tool should be a string to lookup.
-
- To use a tool, please use the following format:
-
- ```
- Question: the input question you must answer
- Thought: your thought about what to do
- Action: the action to take, should be one of [Search, Lookup]
- Action Input: the input to the action
- Observation: the result of the action
- ... (this Thought/Action/Action Input/Observation can repeat N times)
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
- ```
-
- Begin!
-
- Now human has provided the following question.
-
- Question: Author David Chanoff has collaborated with a U.S. Navy admiral who served as the ambassador to the United Kingdom under which President?

Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
[Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
问题: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can
-
- you have access to the following tools:
- [Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [Search, Caculator]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeat N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>

运行结果
- Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his current age raised to the 0.23 power.
- Action: Search
- Action Input: "Who is Olivia Wilde's boyfriend?"
然后我在网上查找一下Olivia Wilde's boyfriend.
搜到如下结果:
Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- you have access to the following tools:
- [Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [Search, Caculator]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeact N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
- Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his current age raised to the 0.23 power.
- Action: Search
- Action Input: "Who is Olivia Wilde's boyfriend?"
- Observation: Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>
执行结果

结果是:
- Thought: I need to find out Harry Styles' current age and then calculate his age raised to the 0.23 power.
- Action: Search
- Action Input: "What is Harry Styles' current age?"
在网上搜索"Harry Styles age"。 结果是:”29 years“
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- you have access to the following tools:
- [Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [Search, Caculator]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeact N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
- Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his current age raised to the 0.23 power.
- Action: Search
- Action Input: "Who is Olivia Wilde's boyfriend?"
- Observation: Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.
- Thought: I need to find out Harry Styles' current age and then calculate his age raised to the 0.23 power.
- Action: Search
- Action Input: "What is Harry Styles' current age?"
- Observation: 29 years
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:
- Thought: I need to calculate Harry Styles' age raised to the 0.23 power.
- Action: Caculator
- Action Input: "29^0.23"
利用计算器计算29 ^ 0.23。 得到:2.169459462491557
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- you have access to the following tools:
- [Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [Search, Caculator]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeact N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?
- Thought: I need to find out who Olivia Wilde's boyfriend is and then calculate his current age raised to the 0.23 power.
- Action: Search
- Action Input: "Who is Olivia Wilde's boyfriend?"
- Observation: Olivia Wilde started dating Harry Styles after ending her years-long engagement to Jason Sudeikis — see their relationship timeline.
- Thought: I need to find out Harry Styles' current age and then calculate his age raised to the 0.23 power.
- Action: Search
- Action Input: "What is Harry Styles' current age?"
- Observation: 29 years
- Thought: I need to calculate Harry Styles' age raised to the 0.23 power.
- Action: Caculator
- Action Input: "29^0.23"
- Observation: 2.169459462491557
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果
Final Answer: The answer to the question "Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?" is Harry Styles, and his current age raised to the 0.23 power is approximately 2.17.
问题:I want to know what privileges does Harry user have ?
工具:[
{tool_name: getUser, description:search user information including pk_user_id based on username, tool parameter: username},
{tool_name: GetRole, description:get role information including role_id based on pk_user_Id, tool parameter: pk_user_Id } ,
{tool_name: GetPrivilege, description:get all privilege based on role_id , tool parameter: role_id }
]
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
-
- you have access to the following tools:
- [
- {tool_name: getUser, description:search user information including pk_user_id based on username, tool parameter: username},
- {tool_name: GetRole, description:get role information including role_id based on pk_user_Id, tool parameter: pk_user_Id } ,
- {tool_name: GetPrivilege, description:get all privilege based on role_id , tool parameter: role_id }
- ]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [GetUser, GetRole, GetPrivilege]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeat N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: I want to know what privileges does Harry user have ?
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:
- Thought: I need to get the user information first
- Action: GetUser
- Action Input: Harry
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
-
- you have access to the following tools:
- [
- {tool_name: getUser, description:search user information including pk_user_id based on username, tool parameter: username},
- {tool_name: GetRole, description:get role information including role_id based on pk_user_Id, tool parameter: pk_user_Id } ,
- {tool_name: GetPrivilege, description:get all privilege based on role_id , tool parameter: role_id }
- ]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [GetUser, GetRole, GetPrivilege]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeat N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: I want to know what privileges does Harry user have ?
- Thought: I need to get the user information first
- Action: GetUser
- Action Input: Harry
- Observation: pk_user_id =1, user_name = Harry, age: 35
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>

结果:
- Thought: Now that I have the user information, I need to get the role of this user
- Action: GetRole
- Action Input: 1
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
-
- you have access to the following tools:
- [
- {tool_name: getUser, description:search user information including pk_user_id based on username, tool parameter: username},
- {tool_name: GetRole, description:get role information including role_id based on pk_user_Id, tool parameter: pk_user_Id } ,
- {tool_name: GetPrivilege, description:get all privilege based on role_id , tool parameter: role_id }
- ]
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [ GetUser, GetRole, GetPrivilege ]
- Action Input: the input to the action
- Observation: the result of the action
- ..(this Thought/Action/Action Input/Observation can repeat N times)
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
-
- Begin!
-
- Question: I want to know what privileges does Harry user have?
- Thought: I need to get the user information first
- Action: GetUser
- Action Input: Harry
- Observation: user id is 1, user_name is Harry, age is35 .
- Thought: Now that I have the user information, I need to get the role of this user
- Action: GetRole
- Action Input: 1
- Observation: role id is 3.
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果有问题,很明显还要根据role id查询privileges.
在prompt里后面追加一个引导词Thought:

结果:
- Action: GetPrivilege
- Action Input: 3
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- If the user demands a final answer but you are unsure, execute the thought/action/action input/observation sequence.
-
- you have access to the following tools:
-
- getUser: search user information including pk user id based on user name
- GetRole: get role information including role id based on pk user Id
- GetPrivilege: get all privilege based on role id
-
-
- To use a tool, please use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [ GetUser, GetRole, GetPrivilege ]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeat N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
-
- Begin!
-
- Now human has provided the following question.
-
- Question: I want to know what privileges does Harry user have?
- Thought: I need to get the user information first
- Action: GetUser
- Action Input: Harry
- Observation: user id is 1, user_name is Harry, age is35 .
- Thought: Now that I have the user information, I need to get the role of this user
- Action: GetRole
- Action Input: 1
- Observation: role id is 3.
- Thought:
- Action: GetPrivilege
- Action Input: 3
- Observation: previleges for role whose role id is 3 are edit account and delete account
- Thought: <|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:
- I now know the final answer
- Final Answer: Harry has privileges to edit account and delete account.
问题:I need to search Apple Remote and find the program it was original designed to interact with.
propmt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- you have access to the following tools:
- [Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [Search, Caculator]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeact N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: I need to search Apple Remote and find the program it was original designed to interact with.
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:
- Thought: I need to find the original purpose of Apple Remote
- Action: Search
- Action Input: "Apple Remote original purpose"
搜索结果:
The Apple Remote is a remote control introduced in October 2005 by Apple. originally designed to control the Front Row media center program.
prompt
- <|begin_of_text|><|start_header_id|>user<|end_header_id|>
- Answer the following questions as best you can.
-
- you have access to the following tools:
- [Search: search the latest information you needs on the internet, Caculator: use it while calculating something ]
-
-
- use the following format:
-
- Question: the input question you must answer
- Thought: you should always think about what to do
- Action: the action to take, should be one of [Search, Caculator]
- Action Input: the input to the action
- Observation: the result of the action
-
- ..(this Thought/Action/Action Input/Observation can repeact N times)
-
- Thought: I now know the final answer
- Final Answer: the final answer to the original input question
-
- Begin!
-
- Question: I need to search Apple Remote and find the program it was original designed to interact with.
- Thought: I need to find the original purpose of Apple Remote
- Action: Search
- Action Input: "Apple Remote"
- Observation: The Apple Remote is a remote control introduced in October 2005 by Apple. originally designed to control the Front Row media center program.
- <|eot_id|><|start_header_id|>assistant<|end_header_id|>

执行结果:
The original program that Apple Remote was designed to interact with is Front Row.
复现失败,找寻答案中。。。
参考资料