# ReAct Pattern

> The ReAct (Reason and Act) is an agent pattern that alternates between reasoning and taking actions with tools.

## What is the ReAct pattern for AI agents?

The pattern where an agent alternates thoughts about what to do next with tool calls and observations of their results. It is the basis of most agent loops.

- Topic: AI Agents
- Type: design pattern

## Example

Wrong:

```js
const res = await llm.generate({ prompt: transcript });
const finalAnswer = res.text.split('Final Answer:')[1];
```

Right:

```js
const res = await llm.generate({ prompt: transcript, stop: ['Observation:'] });
const action = parseAction(res.text);
const observation = await tools[action.name](action.input);
transcript += `${res.text}Observation: ${JSON.stringify(observation)}\n`;
```

Stopping at 'Observation:' makes the code run the real tool, so the model cannot invent the result.

## Common mistakes

- The model invents tool results instead of waiting for them.

## Key points

- Each action is a real tool call, and its observation is the actual tool result.
- The loop has a step limit and a clear final-answer format.
- The model never writes the observation itself; it comes only from the tool.

## Interview questions

### What does a ReAct step look like?

A thought about what to do, an action with a tool and its input, and an observation with the tool result. The loop repeats until a final answer.

### ReAct vs chain-of-thought?

Chain-of-thought only reasons. ReAct interleaves reasoning with actions, so the model can look facts up instead of guessing them.

### Do I need text parsing for ReAct with tool calling?

No. With native tool calling the API returns structured actions, so the same loop runs without parsing 'Action:' lines from text.

## Related cards

- [AI Agent](https://wonderium.dev/ai/ai-agent.md)
- [Chain-of-Thought](https://wonderium.dev/ai/chain-of-thought.md)
- [Tool Calling](https://wonderium.dev/ai/tool-calling.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/react-pattern
- Last updated: 2026-11-25
