ReACT pattern
What we did before is a sequence of steps:
- We call a model
- It decides to call one of the available tools (a calculator) and generates a payload (input) for this tool
- We call the tool and give results back to the model (please note that we send the whole history of our interactions with an LLM since it doesn’t cache it server-side, although sometimes it’s done client-side on the SDK level)
- These steps continue until the model decides to generate a final output that can be passed to a user
In other words, we continuously asked an LLM to reason and then we acted on this reasoning. It is a so-called ReACT pattern. ReACT stands for Reason+Act, and this pattern was introduced in the famous paper published by Google Search and Princeton University (the project resulted from an internship at Google) [7].
Figure 9.1 – ReACT pattern
Let’s look at a very simple example:
react_prompt = ChatPromptTemplate...