ReAct: การให้เหตุผลและการลงมือทำด้วยเครื่องมือ
เรียนรู้รูปแบบ ReAct ซึ่งโมเดลสลับขั้นตอนการให้เหตุผลกับการกระทำผ่านเครื่องมือ เพื่อแก้โจทย์ที่ไม่สามารถตอบได้จากความจำเพียงอย่างเดียว
ReAct: การให้เหตุผลและการลงมือทำด้วยเครื่องมือ เป็นบทเรียน Prompt Engineering & LLM Optimization for Developers ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Prompt Engineering & LLM Optimization for Developers และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Prompt Engineering & LLM Optimization for Developers มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
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.
คำถามที่พบบ่อย
บทเรียน “ReAct: การให้เหตุผลและการลงมือทำด้วยเครื่องมือ” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “ReAct: การให้เหตุผลและการลงมือทำด้วยเครื่องมือ” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Prompt Engineering & LLM Optimization for Developers ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Prompt Engineering & LLM Optimization for Developers มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “ReAct: การให้เหตุผลและการลงมือทำด้วยเครื่องมือ”
เรียนรู้รูปแบบ ReAct ซึ่งโมเดลสลับขั้นตอนการให้เหตุผลกับการกระทำผ่านเครื่องมือ เพื่อแก้โจทย์ที่ไม่สามารถตอบได้จากความจำเพียงอย่างเดียว คุณปฏิบัติ Prompt Engineering & LLM Optimization for Developers ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Prompt Engineering & LLM Optimization for Developers หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Prompt Engineering & LLM Optimization for Developers บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน
บทเรียน “ReAct: การให้เหตุผลและการลงมือทำด้วยเครื่องมือ” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Prompt Engineering & LLM Optimization for Developers นี้ได้ไหม
ได้ บทเรียน Prompt Engineering & LLM Optimization for Developers ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การเขียนพรอมต์แบบ Chain-of-Thought
- ความสอดคล้องในตนเองและความรู้ที่สร้างขึ้น
- พรอมต์แบบ Tree-of-Thought และกราฟ
- ReAct: การให้เหตุผลและการลงมือทำด้วยเครื่องมือ