Introduction
When AI systems try to solve complex problems, they often need to think and act step-by-step. The ReAct pattern helps AI do this by combining reasoning and actions in a clear way.
Jump into concepts and practice - no test required
Imagine you are assembling a puzzle. You look at the pieces (reasoning), then try to fit one piece in place (action). If it doesn't fit, you think again and try a different piece, repeating until the puzzle is complete.
┌───────────┐ ┌───────────┐
│ Reasoning │ →→ │ Action │
└───────────┘ └───────────┘
↑ ↓
└────── Loop ────┘ReAct pattern in AI?thought = 'Check weather'
action = 'Query weather API'
observation = 'It is sunny'
final_answer = f"Weather is {observation}"
print(final_answer)observation holds the string 'It is sunny'. The final_answer uses this to create 'Weather is It is sunny'.final_answer string, which is 'Weather is It is sunny' because the f-string inserts the full observation string.thought = 'Calculate sum' action = 'Add 2 and 3' observation = 2 + 3 final_answer = 'Sum is ' + observation print(final_answer)
str(observation) before concatenation.