How to use LangChain

How to use LangChain is a practical five-step roadmap:

1) Install the packages you need: pip install langchain langchain-openai covers the core path, and pip install langchain-community adds the community integrations. Set your OPENAI_API_KEY (or other model key) as an environment variable.

2) Load data using your choice of DocumentLoader — PDF, web page, or database — and turn raw text into Document objects.

3) Split and embed that text with TextSplitter and the embedding model; store the vectors in Chroma, Qdrant, or another supported database.

4) Build logic with a chain or agent — start simple with an LCEL pipeline (prompt | model | parser) for single-query tasks, then compose a retriever with a chat model for retrieval-augmented generation, or use create_agent from langchain.agents for tool calling. The older LLMChain, RetrievalQA and initialize_agent APIs were deprecated and now live in langchain-classic.

5) Observe and deploy by adding callback handlers for token streaming, cost tracking, and debugging, then wrap the chain in FastAPI, Streamlit, or AWS Lambda. Because each component is plug-and-play, you can swap providers (OpenAI ↔ Anthropic), databases, or prompt templates without rewriting the core code, allowing you to move prototypes into production in days.

Work with us

Ready to put agentic AI to work?

Book a free 45-minute consultation. We'll map one real process worth automating with production-grade AI.