0Pricing
AI Agents with LangChain & Autonomous Workflows · Leçon

Explication des composants fondamentaux de LangChain

Découvrez les éléments essentiels de LangChain, notamment les LLM, les invites, les chaînes et les agents, ainsi que leurs interactions.

Explication des composants fondamentaux de LangChain est une leçon AI Agents with LangChain & Autonomous Workflows gratuite sur CoddyKit. Ceci est la leçon 2 sur 4. Tu peux lire la leçon complète ci-dessous gratuitement — puis la pratiquer en direct dans le navigateur avec un éditeur de code intégré et un tuteur IA 24/7. Elle fait partie du parcours d'apprentissage AI Agents with LangChain & Autonomous Workflows, et ta progression se synchronise sur le web et l'application CoddyKit. Le cours AI Agents with LangChain & Autonomous Workflows comprend 4 leçons au total.

Certaines parties de cette leçon n'ont pas encore été traduites et s'affichent en anglais.

Welcome to LangChain Core!

Now meet LangChain, a framework for building agents. It gives you modular components you snap together like LEGO bricks.

The Brain: Large Language Models (LLMs)

The agent's brain is the LLM — a model trained on vast text to understand and generate language. LangChain makes it easy to plug into GPT or open-source models.

LLM in Action: A Simple Call

Here's a basic LLM call in LangChain, using a fake model so it runs without any 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

An LLM needs instructions, and those are your prompts — the input text you feed it. Good prompts are crucial for getting the output you want.

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.

Questions Fréquemment Posées

La leçon « Explication des composants fondamentaux de LangChain » est-elle gratuite ?

Oui — le texte complet de « Explication des composants fondamentaux de LangChain » est gratuit à lire ici sur le web. Pour la pratiquer de manière interactive (un éditeur de code intégré et un tuteur IA 24/7) et déverrouiller le reste du cours AI Agents with LangChain & Autonomous Workflows, passe à CoddyKit PRO. Le cours AI Agents with LangChain & Autonomous Workflows comprend 4 leçons au total.

Qu'est-ce que j'apprendrai dans « Explication des composants fondamentaux de LangChain » ?

Découvrez les éléments essentiels de LangChain, notamment les LLM, les invites, les chaînes et les agents, ainsi que leurs interactions. Tu pratiques AI Agents with LangChain & Autonomous Workflows avec du code pratique que tu exécutes directement dans le navigateur, et un tuteur IA 24/7 répond à tes questions au fur et à mesure que tu avances dans la leçon.

Dois-je avoir de l'expérience pour commencer AI Agents with LangChain & Autonomous Workflows ?

Aucune expérience préalable n'est requise. AI Agents with LangChain & Autonomous Workflows sur CoddyKit est structuré pour les débutants jusqu'aux apprenants avancés, donc tu peux commencer ici ou depuis le début et avancer à ton rythme. Ceci est la leçon 2 sur 4.

Combien de temps prend la leçon « Explication des composants fondamentaux de LangChain » ?

La plupart des leçons CoddyKit prennent environ 5–10 minutes. Chacune est courte et interactive, tu progresses régulièrement et tu repiques exactement où tu t'es arrêté sur le web et l'app.

Peux-tu écrire et exécuter du code dans cette leçon AI Agents with LangChain & Autonomous Workflows ?

Oui. Chaque leçon AI Agents with LangChain & Autonomous Workflows inclut un éditeur de code intégré, tu écris et exécutes du vrai code directement dans ton navigateur et tu reçois des retours IA instantanés — aucune configuration locale requise.

Toutes les leçons de ce cours

  1. Comprendre les agents d’intelligence artificielle et les LLM
  2. Explication des composants fondamentaux de LangChain
  3. Construire votre premier agent simple
  4. Doter les agents d’une mémoire et d’un état conversationnel
← Retour à AI Agents with LangChain & Autonomous Workflows