---
title: "The ReAct Pattern for LLMs | XingKaiXin's Upside Down"
description: "A prompt pattern for large language models that uses structured controls so the model can invoke external tools to solve problems."
canonical: "https://xingkaixin.me/en/posts/llm-react-prompt/"
language: "en"
---

# 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 read[Read Chinese original](https://xingkaixin.me/posts/llm-react-prompt/)

[LLM](https://xingkaixin.me/tags/LLM/)Prompt

![The ReAct Pattern for LLMs](https://xingkaixin.me/cover/llm-react-prompt-800.01570c30.webp)

AI TranslationAI-translated from Chinese · Site UI stays in English.

Reference paper:

[ReAct: Synergizing Reasoning and Acting in Language Models](https://arxiv.org/abs/2210.03629)

### Implementation Diagrams

![ReAct flow diagram](https://xingkaixin.me/posts/images/llm-react-prompt/react.6f31bec4.webp)

![Example output](https://xingkaixin.me/posts/images/llm-react-prompt/output.b6a1f0f5.webp)

### 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.

文中链接

1.  ReAct: Synergizing Reasoning and Acting in Language Modelshttps://arxiv.org/abs/2210.03629

Zoomed illustration

## Copyright

Author

XingKaiXin

Title

The ReAct Pattern for LLMs

Published

2023年4月11日

Permalink

[https://xingkaixin.me/en/posts/llm-react-prompt/](https://xingkaixin.me/en/posts/llm-react-prompt/)

Licensed under [CC BY-NC-ND 4.0 DEED](https://creativecommons.org/licenses/by-nc-nd/4.0/deed.en).

XingKaiXin

Highlights · 0

Contents

Highlights · 0

## Contents

Highlights · 0
