DEV Community

Cover image for Day 4: ReAct - Reasoning + Acting upon(Prompting Technique)
Suraj Bera
Suraj Bera

Posted on • Edited on

Day 4: ReAct - Reasoning + Acting upon(Prompting Technique)

Big picture of ReAct:

AI doesn't just answer immediately, it goes through stages.
think -> plan -> action -> observe -> output(total 5 steps)

ReAct = Forcing the AI to show its work step by step before arriving at a conclusion, just like how a student arrives to the solution of a math problem step by step.

Here is the simplest mental model for ReAct:


┌──────────────────────────────┐   ┌──────────────────────────────┐   ┌──────────────────────────────┐
│ Current State / User Question│ → │ Reason about current state   │ → │ Need more action?            │
└──────────────────────────────┘   └──────────────────────────────┘   └──────────────┬───────────────┘
                                                                                       │
                                                                           ┌───────────┴───────────┐
                                                                           │                       │
                                                                          Yes                      No
                                                                           │                       │
                                                                           v                       v
                                                ┌──────────────────────────────┐   ┌──────────────────────────────┐
                                                │ Choose tool / perform action │   │ Return final answer          │
                                                └──────────────┬───────────────┘   └──────────────────────────────┘
                                                               │
                                                               v
                                                ┌──────────────────────────────┐
                                                │ Observe result               │
                                                └──────────────┬───────────────┘
                                                               │
                                                               └──── back to "Reason about current state"

Enter fullscreen mode Exit fullscreen mode

Comparing Chain of Thought(another prompting technique) vs ReAct:
CoT - In this technique, the LLM is instructed to generate its intermediate reasoning steps as part of the output, instead of jumping straight to the final answer.
ReAct - CoT only thinks, ReAct thinks and does stuffs.

Here is the code

Links to Day 3 and Day 2

Top comments (0)