Prompt Engineering & LLM Optimization for Developers · Aula

ReAct: Raciocinando e Agindo com Ferramentas

Aprenda o padrão ReAct, no qual o modelo intercala etapas de raciocínio com ações de ferramentas para resolver tarefas que não consegue responder apenas com a memória.

Aula 4 de 413 etapas

ReAct: Raciocinando e Agindo com Ferramentas é uma aula grátis de Prompt Engineering & LLM Optimization for Developers no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Prompt Engineering & LLM Optimization for Developers, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Prompt Engineering & LLM Optimization for Developers inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

When Thinking Is Not Enough

Chain-of-thought helps a model reason, but reasoning alone cannot fetch live data or run code. The ReAct pattern combines Reasoning with Acting so the model can use tools mid-task.

The ReAct Loop

ReAct alternates three roles in a loop:

  • Thought: reason about what to do next.
  • Action: call a tool with an input.
  • Observation: read the tool's result.

Repeat until the answer is ready.

A ReAct Trace

A typical trace looks like this. The model emits a thought, an action, then waits for an observation injected back into the prompt.

Thought: I need today's weather in Paris.
Action: get_weather("Paris")
Observation: 18C, light rain
Thought: I can now answer.
Answer: It is 18C with light rain in Paris.

Defining the Tools

You describe the available tools in the prompt: their names, what they do, and the input format. The model picks among them.

Tools:
- search(query): web search
- calc(expr): evaluate math
- get_weather(city): current weather

Stopping at the Action

In practice your code stops generation when it sees an Action, executes the real tool, then appends the Observation and resumes the model. The model never invents tool results itself.

Why It Reduces Hallucination

Because the model grounds each step in real observations, ReAct cuts hallucination on factual or computational tasks. The reasoning explains why each tool was called, aiding debugging.

Multi-Step Problems

ReAct shines on tasks needing several lookups: find a company, then its founder, then that person's birth year. Each step's observation feeds the next thought.

Limiting the Loop

Always cap the number of iterations. Without a limit, a confused model can loop forever calling tools. Add a max-step budget and a fallback answer.

for step in range(MAX_STEPS):
    out = model(prompt)
    if is_answer(out): break
    obs = run_tool(parse_action(out))
    prompt += observation(obs)

Handling Tool Errors

Tools fail: timeouts, bad inputs, empty results. Feed the error back as an observation so the model can retry differently rather than crashing the loop.

Observation: ERROR: city not found.
Thought: I should try the full country name.

ReAct vs Plain Chain-of-Thought

  • CoT: reasons internally, no external data.
  • ReAct: reasons AND acts on the world via tools.

Use ReAct whenever the answer depends on information the model cannot already know.

Foundation for Agents

ReAct is the backbone of modern LLM agents. Frameworks like LangChain implement this thought-action-observation loop under the hood to build autonomous tool-using assistants.

Quick Check

Test your understanding of ReAct.

Recap

ReAct interleaves Thought, Action, and Observation so the model reasons and uses real tools. It grounds answers, reduces hallucination, needs a step limit and error handling, and underpins modern LLM agents.

Grátis para começar

Aprenda Prompt Engineering & LLM Optimization for Developers com um tutor de IA — grátis

Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.

Cursos
12
Aulas
48

Perguntas Frequentes

A aula “ReAct: Raciocinando e Agindo com Ferramentas” é grátis?

Sim — o texto completo de “ReAct: Raciocinando e Agindo com Ferramentas” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Prompt Engineering & LLM Optimization for Developers, atualize para CoddyKit PRO. O curso de Prompt Engineering & LLM Optimization for Developers inclui 4 aulas no total.

O que vou aprender em “ReAct: Raciocinando e Agindo com Ferramentas”?

Aprenda o padrão ReAct, no qual o modelo intercala etapas de raciocínio com ações de ferramentas para resolver tarefas que não consegue responder apenas com a memória. Você pratica Prompt Engineering & LLM Optimization for Developers com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Prompt Engineering & LLM Optimization for Developers?

Nenhuma experiência prévia é necessária. Prompt Engineering & LLM Optimization for Developers no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.

Quanto tempo leva a aula “ReAct: Raciocinando e Agindo com Ferramentas”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Prompt Engineering & LLM Optimization for Developers?

Sim. Cada aula de Prompt Engineering & LLM Optimization for Developers inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Criação de prompts com cadeia de pensamento
  2. Autoconsistência e conhecimento gerado
  3. Prompts em árvore de pensamento e em grafo
  4. ReAct: Raciocinando e Agindo com Ferramentas
← Voltar para Prompt Engineering & LLM Optimization for Developers