ReAct框架详解与思考

ReAct提示词

Posted by LuochuanAD on February 11, 2026 本文总阅读量

背景

在各种论文中, 有多种智能Agent的推理逻辑(也称框架):CoT, ToT, LLM+P等, 其中ReAct框架被LanggChain和LlamaIndex等多种AI应用开发工具作为推理引擎.

ReAct框架

ReAct: Synergizing Reasoning and Acting in Language Models

PromptTemplate(
	input_variables = ['agent_scratchpad', 'input', 'tool_name', 'tools'],
	template = 'Answer the folllowing questions as best you can.
		You have access to the folowing tools: \n\n{tools}\n\n
		Use the following format: \n\n
		Question: the input question you must answer \n
		Thought: you should always think about what to do \n
		Action: the action to take, should be one of [{tool_names}] \n
		Action input: the input to the action \n...\n
		Observation: the result of the action \n...\n
		(this Thought/ Action/ Action Input/ Observation can repeat 3 times) \n
		Thought: I now know the final answer \n
		Final Answer: the final answer to the original input questions \n\n Begain! \n\n
		Questions: {input} \n
		Thought: {agent_scratchpad}'
)

在实例化过程中, 这个提示会引导一个大模型使用特定的格式来回答问题,此过程包括思考, 行动,行动输入, 观察. 并根据需要重复3次得到最终的答案.

参考

LangChina官网: hwchase17/react