Skip to content
中文
← PostsThe ReAct Pattern for LLMs

The ReAct Pattern for LLMs

A prompt pattern for large language models that uses structured controls so the model can invoke external tools to solve problems.

2023年4月11日·48 words·1 min readRead Chinese original
LLMPrompt
The ReAct Pattern for LLMs

Reference paper:

ReAct: Synergizing Reasoning and Acting in Language Models

Implementation Diagrams

ReAct flow diagram

Example output

Prompt

Answer the following questions as best you can. You have access to the following tools:
CalculatorTool: Runs calculations and returns a number - uses Python.
GithubUserInfoTool: Returns GitHub user information, including location, bio, follower count, following count, public repository count, creation time, etc., formatted as JSON. The action input is a GitHub username (without quotes).
Write each step in the following format. You can take multiple steps, but do not number them. If the tools provided above cannot answer the question, feel free to improvise and start your reply with "Final Answer:".
For matters unrelated to the tools above, you do not need the Thought and Action pattern.
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 [CalculatorTool, GithubUserInfoTool] (if needed, do not output multiple Actions at once).
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

Core Mechanism

To implement this pattern, pass stop in the API request so the gpt model halts when it reaches a specified token. Your code can then execute the requested Action, supply the Observation, and send the next request.

Copyright

Author
XingKaiXin
Title
The ReAct Pattern for LLMs
Published
2023年4月11日

Licensed under CC BY-NC-ND 4.0 DEED.

XingKaiXinXingKaiXin

Stamp book

0 / 10
  • 初来乍到Visit for the first time
  • 颠倒世界Flip the world once
  • 手不释卷Read a post to the end
  • 愿者上钩Fish something out of the pond
  • 余音绕梁Play the record to the end
  • 手下留情Pinch Kaixin's cheek
  • 暗房一游See the photos in the darkroom
  • 误入歧途Find a page that doesn't exist
  • 夜深人静Drop by late at night
  • 终端潜行Successfully run cat or mcp call in the Agent shell

Stamps are kept only in this browser