背景
論文において、さまざまなスマートエージェントの推論ロジック(フレームワークとも呼ばれる)が提案されています:CoT、ToT、LLM+Pなど。その中で、ReActフレームワークはLangChainや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回繰り返して最終回答を導き出します。
参考
LangChain公式サイト: hwchase17/react