0Pricing
AI Agents with LangChain & Autonomous Workflows · درس

شرح المكونات الأساسية لـ LangChain

تعلّم حول اللبنات الأساسية لـ LangChain، بما في ذلك LLMs وPrompts وChains وAgents، وكيفية تفاعلها

شرح المكونات الأساسية لـ LangChain درس مجاني في AI Agents with LangChain & Autonomous Workflows على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في AI Agents with LangChain & Autonomous Workflows، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة AI Agents with LangChain & Autonomous Workflows 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Welcome to LangChain Core!

تعرف الآن على LangChain، وهو إطار عمل بناء الوكلاء. يمنحك مكونات قياسية تركبها معاً مثل قطع ليغو (LEGO).

The Brain: Large Language Models (LLMs)

عقل الوكيل هو نموذج LLM — وهو نموذج مدرب على كميات هائلة من النصوص لفهم اللغة وتوليدها. تسهل مكتبة LangChain ربطه بنماذج GPT أو النماذج مفتوحة المصدر.

LLM in Action: A Simple Call

إليك استدعاء أساسي لـ نموذج لغوي كبير (LLM) في LangChain، باستخدام نموذج وهمي ليعمل بدون أي مفتاح واجهة برمجة تطبيقات (API Key).

from langchain_core.llms import FakeListLLM

# Our 'brain' that gives predefined answers
llm = FakeListLLM(responses=[
    "The capital of France is Paris.",
    "Hello! How can I help you today?"
])

# Ask the LLM a question
response = llm.invoke("What is the capital of France?")
print(response)

Guiding the Brain: Prompts

يحتاج نموذج اللغة الكبير إلى تعليمات، وهذه هي توجيهاتك (prompts) — وهي النص الذي تدخله إليه. التوجيهات الجيدة بالغة الأهمية للحصول على النتيجة التي تريدها.

Dynamic Prompts: Prompt Templates

For input that changes, use a prompt template: a reusable blueprint with placeholders you fill in at runtime.

from langchain_core.prompts import PromptTemplate

# Define a template with a placeholder '{topic}'
qa_template = """
Answer the following question about {topic}:

Question: {question}
"""

# Create a PromptTemplate object
prompt = PromptTemplate.from_template(qa_template)

# Format the prompt with specific values
formatted_prompt = prompt.format(
    topic="Python programming", 
    question="What is a variable?"
)
print(formatted_prompt)

Connecting Steps: Chains

Most agent tasks take several steps. A chain is a predefined sequence that wires LLMs, prompts, and utilities together, passing each output into the next step.

Building a Simple Chain

Here's a simple chain: a prompt template piped into an LLM using LangChain's Runnable interface. The prompt's output feeds straight into the model.

from langchain_core.llms import FakeListLLM
from langchain_core.prompts import PromptTemplate

# 1. Our 'brain'
llm = FakeListLLM(responses=["A variable is a named storage location."])

# 2. Our prompt template
qa_template = """
Explain {concept} in simple terms.
"""
prompt = PromptTemplate.from_template(qa_template)

# 3. Combine them into a chain using '|' operator
# The prompt output goes into the LLM as input
chain = prompt | llm

# Invoke the chain with the input for the template
response = chain.invoke({"concept": "variable"})
print(response)

The Orchestrator: Agents

Chains run fixed steps; agents are dynamic. An agent decides which action to take, runs it, observes the result, and repeats until the goal is met.

How Agents Use Components

Agents tie it all together: LLMs for reasoning, prompts to guide thinking, chains for multi-step work, and tools to act on the real world.

Putting it All Together

Picture a smart assistant: a prompt sets the task, the LLM reasons, a chain processes input, and the agent picks a weather tool — then the LLM formats the answer.

Quick Check: Core Components

Which LangChain component is primarily responsible for dynamic decision-making and tool selection in an AI application?

Recap & Next Steps

Recap: the four LangChain building blocks — LLMs (the brain), prompts (instructions), chains (sequences), and agents (dynamic deciders). Next: build one.

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

هل درس «شرح المكونات الأساسية لـ LangChain» مجاني؟

نعم — نص درس «شرح المكونات الأساسية لـ LangChain» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة AI Agents with LangChain & Autonomous Workflows، انتقل إلى CoddyKit PRO. تتضمن دورة AI Agents with LangChain & Autonomous Workflows 4 دروس في المجموع.

ماذا ستتعلم في «شرح المكونات الأساسية لـ LangChain»؟

تعلّم حول اللبنات الأساسية لـ LangChain، بما في ذلك LLMs وPrompts وChains وAgents، وكيفية تفاعلها تتمرن على AI Agents with LangChain & Autonomous Workflows مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ AI Agents with LangChain & Autonomous Workflows؟

لا تُشترط خبرة سابقة. AI Agents with LangChain & Autonomous Workflows على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.

كم من الوقت يستغرق درس «شرح المكونات الأساسية لـ LangChain»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس AI Agents with LangChain & Autonomous Workflows هذا؟

نعم. كل درس في AI Agents with LangChain & Autonomous Workflows يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

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

  1. فهم وكلاء الذكاء الاصطناعي ونماذج اللغة الكبيرة
  2. شرح المكونات الأساسية لـ LangChain
  3. بناء أول وكيل بسيط لك
  4. إضافة الذاكرة وحالة المحادثة إلى الوكلاء
← العودة إلى AI Agents with LangChain & Autonomous Workflows