LangChain's modular design lets developers mix and match components like chains and memory. This makes building complex applications easier and faster.
Memory in LangChain stores past interactions so the chatbot can maintain context, making conversations feel natural and connected.
Option A correctly imports PromptTemplate and LLMChain, defines the prompt with input variables, creates an LLM instance, and combines them into a chain.
from langchain.agents import initialize_agent from langchain.llms import OpenAI llm = OpenAI() agent = initialize_agent(llm) response = agent.run("Tell me a joke.")
initialize_agent needs both an LLM and a list of tools to work. Providing only the LLM causes a TypeError.
from langchain.chains import ConversationChain from langchain.memory import ConversationBufferMemory from langchain.llms import OpenAI memory = ConversationBufferMemory() llm = OpenAI() chain = ConversationChain(llm=llm, memory=memory) chain.run("Hello!") output = chain.run("How are you?")
ConversationBufferMemory keeps track of past inputs and outputs, so the LLM response to 'How are you?' includes context from 'Hello!'.
