ReAct: rozumowanie i działanie za pomocą narzędzi
Poznaj wzorzec ReAct, w którym model przeplata etapy rozumowania z działaniami narzędzi, aby rozwiązywać zadania, na które nie potrafi odpowiedzieć wyłącznie z pamięci.
ReAct: rozumowanie i działanie za pomocą narzędzi to bezpłatna lekcja Prompt Engineering & LLM Optimization for Developers na CoddyKit. To lekcja 4 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Prompt Engineering & LLM Optimization for Developers, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Prompt Engineering & LLM Optimization for Developers zawiera 4 lekcji w sumie.
Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.
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 weatherStopping 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.
Często zadawane pytania
Czy lekcja „ReAct: rozumowanie i działanie za pomocą narzędzi” jest bezpłatna?
Tak — pełny tekst „ReAct: rozumowanie i działanie za pomocą narzędzi” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Prompt Engineering & LLM Optimization for Developers, przejdź na CoddyKit PRO. Kurs Prompt Engineering & LLM Optimization for Developers zawiera 4 lekcji w sumie.
Co nauczysz się w „ReAct: rozumowanie i działanie za pomocą narzędzi”?
Poznaj wzorzec ReAct, w którym model przeplata etapy rozumowania z działaniami narzędzi, aby rozwiązywać zadania, na które nie potrafi odpowiedzieć wyłącznie z pamięci. Ćwiczysz Prompt Engineering & LLM Optimization for Developers z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.
Czy potrzebuję doświadczenia, aby zacząć Prompt Engineering & LLM Optimization for Developers?
Nie wymagamy żadnego doświadczenia. Prompt Engineering & LLM Optimization for Developers w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 4 z 4.
Ile czasu zajmuje lekcja „ReAct: rozumowanie i działanie za pomocą narzędzi”?
Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.
Czy mogę pisać i uruchamiać kod w tej lekcji Prompt Engineering & LLM Optimization for Developers?
Tak. Każda lekcja Prompt Engineering & LLM Optimization for Developers zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.
Wszystkie lekcje w tym kursie
- Promptowanie Chain-of-Thought
- Samospójność i wiedza generowana
- Promptowanie Tree-of-Thought i Graph
- ReAct: rozumowanie i działanie za pomocą narzędzi