LangChain is a framework that ‘chains’ different components to create complex and flexible solutions with multiple LLMs. This is useful when the task is too complex for a specific LLM alone.

LangChain abstracts common AI programming concepts into unified interfaces and provides a robust implementation. You can easily swap out your AI model with a different one without having to change your applications.

The four main components in LangChain are Agents, LLMs, Prompt Templates and Memory.

In LangChain, PromptTemplate is responsible for constructing the input to an AI model, and the constructed result is represented by the PromptValue class (returned by the formatPromptValue of a PromptTemplate), which can be converted to a string or list of ChatMessage objects.

Abstracting the prompt enables the same prompt to be used in different model types by converting it into the exact input type each model expects. A PromptValue is often dynamically constructed by various inputs to the PromptTemplate.

References