0Pricing
Prompt Engineering & LLM Optimization for Developers · درس

ReAct: الاستدلال وتنفيذ الإجراءات باستخدام الأدوات

تعلّم نمط ReAct، الذي يتناوب فيه النموذج بين خطوات الاستدلال وتنفيذ إجراءات الأدوات لحل المهام التي لا يستطيع الإجابة عنها من ذاكرته وحدها.

ReAct: الاستدلال وتنفيذ الإجراءات باستخدام الأدوات درس مجاني في Prompt Engineering & LLM Optimization for Developers على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 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.

الأسئلة الشائعة

هل درس «ReAct: الاستدلال وتنفيذ الإجراءات باستخدام الأدوات» مجاني؟

نعم — نص درس «ReAct: الاستدلال وتنفيذ الإجراءات باستخدام الأدوات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 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 مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 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 يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. هندسة المطالبات القائمة على سلسلة الأفكار
  2. الاتساق الذاتي والمعرفة المُولّدة
  3. مطالبات شجرة الأفكار والرسوم البيانية
  4. ReAct: الاستدلال وتنفيذ الإجراءات باستخدام الأدوات
← العودة إلى Prompt Engineering & LLM Optimization for Developers