Hitesh Sahu
Hitesh SahuHitesh Sahu
  1. Home
  2. ›
  3. posts
  4. ›
  5. …

  6. ›
  7. 2 5 LangChain

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🤯 Your stomach gets a new lining every 3–4 days.

🍪 This website uses cookies

No personal data is stored on our servers however third party tools Google Analytics cookies to measure traffic and improve your website experience. Learn more

Loading ⏳
Fetching content, this won’t take long…


💡 Did you know?

🍯 Honey never spoils — archaeologists found 3,000-year-old jars still edible.
Cover Image for LangChain and AI Agent Orchestration: RAG, LLM Workflows, Vector Databases and Tool Calling

LangChain and AI Agent Orchestration: RAG, LLM Workflows, Vector Databases and Tool Calling

Comprehensive overview of LangChain covering AI agents, Retrieval-Augmented Generation (RAG), prompt orchestration, tool calling, memory management, vector databases, multi-step LLM workflows, and production GenAI application development.

Hitesh Sahu
Written by Hitesh Sahu, a passionate developer and blogger.

Tue May 19 2026

Share This on

← Previous

ONNX (Open Neural Network Exchange): Portable AI Models, TensorRT and Cross-Framework Inference

Next →

Megatron-LM and Distributed LLM Training: Tensor Parallelism, NCCL and Trillion-Scale AI Models

LangChain ⛓️

LangChain is an open-source framework for building applications powered by Large Language Models (LLMs).

It helps developers build:

  • chatbots
  • AI agents
  • RAG systems
  • workflow automation
  • tool-using AI systems
  • multi-step reasoning pipelines

LangChain provides abstractions for:

  • prompts
  • memory
  • tools
  • retrieval
  • chains
  • agents
  • vector databases

Why LangChain Exists

Raw LLM APIs are limited. You need to build your own setup to call LLM.

Also, it does not have RAG to expand its knowledge base

An LLM alone:

  • cannot access external tools
  • cannot retrieve enterprise knowledge
  • cannot maintain complex workflows
  • cannot orchestrate multi-step reasoning easily

LangChain adds orchestration around LLMs.

LangChain vs Raw LLM APIs

  • LLM: Generates text
  • LangChain: Coordinates AI workflows around the LLM
Feature Raw LLM API LangChain
Basic prompting Yes Yes
Multi-step workflows Limited Excellent
Tool calling Manual Built-in
RAG pipelines Manual Excellent
Memory Manual Built-in
Agent systems Difficult Easier

LangChain vs NeMo

Feature LangChain NeMo
AI orchestration Excellent Moderate
LLM training No Excellent
RAG pipelines Excellent Excellent
Enterprise GPU optimization Limited Excellent
Inference optimization No Strong
Ease of prototyping Excellent Moderate

LangGraph

LangChain now heavily promotes:

LangGraph

for advanced agent workflows.

LangGraph enables:

  • stateful workflows
  • multi-agent systems
  • retries
  • branching execution
  • durable execution
from langgraph.graph import StateGraph, MessagesState, START, END

def mock_llm(state: MessagesState):
    return {"messages": [{"role": "ai", "content": "hello world"}]}

graph = StateGraph(MessagesState)
graph.add_node(mock_llm)
graph.add_edge(START, "mock_llm")
graph.add_edge("mock_llm", END)
graph = graph.compile()

graph.invoke({"messages": [{"role": "user", "content": "hi!"}]})

LangChain vs. LangGraph vs. Deep Agents

Start with Deep Agents for a “batteries-included” agent with features like automatic context compression, a virtual filesystem, and subagent-spawning.

  • Deep Agents are built on LangChain agents which you can also use LangChain directly.

Use LangGraph for low-level orchestration framework

  • for advanced needs combining deterministic and agentic workflows.

Use LangSmith to trace, debug, and evaluate agents built with any of these frameworks.


High-Level LangChain Architecture

flowchart TD

    A["User Input"]
        --> B["LangChain Orchestration"]

    B --> C["LLM"]

    B --> D["Tools"]

    B --> E["Retriever"]

    B --> F["Memory"]

    C --> G["Final Response"]
    D --> G
    E --> G
    F --> G

Core LangChain Components

Component Purpose
LLMs Text generation
Prompts Structured instructions
Chains Multi-step workflows
Agents Dynamic decision-making
Tools External APIs/functions
Memory Conversation state
Retrievers Knowledge retrieval
Vector Stores Embedding storage

Typical Production Stack

flowchart TD

    A["Frontend App"]
        --> B["LangChain"]

    B --> C["Retriever"]

    B --> D["LLM"]

    D --> E["Triton / OpenAI / vLLM"]

    C --> F["Vector Database"]

Why LangChain Became Popular

It dramatically simplifies:

  • RAG pipelines
  • AI agents
  • tool calling
  • workflow orchestration
  • multi-step reasoning systems

for developers building production GenAI applications.


# pip install -qU langchain "langchain[openai]"
from langchain.agents import create_agent

def get_weather(city: str) -> str:
    """Get weather for a given city."""
    return f"It's always sunny in {city}!"

agent = create_agent(
    model="openai:gpt-5.4",
    tools=[get_weather],
    system_prompt="You are a helpful assistant",
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}
)
print(result["messages"][-1].content_blocks)

Example LangChain Flow

1. Prompts

Prompts define how the model behaves.

Example:

from langchain.prompts import PromptTemplate

prompt = PromptTemplate.from_template(
    "Explain {topic} in simple terms"
)

2. Chains

Chains connect multiple operations together called chain.

Example:

flowchart TD

    A["User Question"]
        --> B["Retriever"]

    B --> C["LLM"]

    C --> D["Formatted Answer"]

Example:

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4")

response = llm.invoke("Explain CUDA")

3. Agents

Agents allow the LLM to decide:

  • which tool to use
  • when to call APIs
  • how to solve multi-step tasks

Example:

flowchart TD

    A["User Request"]
        --> B["LLM Agent"]

    B --> C["Search Tool"]

    B --> D["Calculator"]

    B --> E["Database"]

    C --> F["Final Answer"]
    D --> F
    E --> F

Example

from langchain.agents import create_agent
from langchain_openai import ChatOpenAI

model = ChatOpenAI(
    model="gpt-5.4",
    temperature=0.1,
    max_tokens=1000,
    timeout=30
    # ... (other params)
)
agent = create_agent(model, tools=tools)

Modern AI agents often use:

flowchart TD

    A["LLM"]
        --> B["Reasoning"]

    B --> C["Tool Selection"]

    C --> D["External APIs"]

    D --> E["Observation"]

    E --> F["Final Response"]

4. Tools

Extend what agents can do—letting them fetch real-time data, execute code, query external databases, and take actions in the world.

LangChain tools connect LLMs to external systems.

Examples:

  • web search
  • SQL databases
  • APIs
  • Python execution
  • vector databases

Example:

from langchain.tools import tool

@tool
def search_database(query: str, limit: int = 10) -> str:
    """Search the customer database for records matching the query.

    Args:
        query: Search terms to look for
        limit: Maximum number of results to return
    """
    return f"Found {limit} results for '{query}'"

5. Short Term Memory

system that remembers information about previous interactions.

Memory stores conversation context.

Example:

  • previous user messages
  • chat history
  • session context

Without memory:

  • chatbots forget earlier conversations.

In Memory storage for Dev/QA

from langchain.agents import create_agent
from langgraph.checkpoint.memory import InMemorySaver  


agent = create_agent(
    "gpt-5.4",
    tools=[get_user_info],
    checkpointer=InMemorySaver(),
)

agent.invoke(
    {"messages": [{"role": "user", "content": "Hi! My name is Bob."}]},
    {"configurable": {"thread_id": "1"}},
)

DB checkpoint for PROD


from langchain.agents import create_agent

from langgraph.checkpoint.postgres import PostgresSaver  


DB_URI = "postgresql://postgres:postgres@localhost:5432/postgres?sslmode=disable"
with PostgresSaver.from_conn_string(DB_URI) as checkpointer:
    checkpointer.setup() # auto create tables in PostgreSQL
    agent = create_agent(
        "gpt-5.4",
        tools=[get_user_info],
        checkpointer=checkpointer,
    )
    

6. Retrieval (RAG)

LangChain is widely used for:

Retrieval-Augmented Generation (RAG)

Pipeline:

flowchart TD

    A["Documents"]
        --> B["Embeddings"]

    B --> C["Vector DB"]

    D["User Query"]
        --> E["Retriever"]

    E --> C

    C --> F["Relevant Context"]

    F --> G["LLM"]

LangChain + Vector Databases

Supported vector stores:

  • FAISS
  • Pinecone
  • Weaviate
  • Chroma
  • Milvus
  • Elasticsearch

LangChain + LLM Providers

LangChain supports:

  • OpenAI
  • Anthropic
  • Gemini
  • Ollama
  • Hugging Face
  • NVIDIA NIM
  • local models

Common LangChain Use Cases

  • AI copilots
  • Chatbots
  • RAG systems
  • AI agents
  • Document Q&A
  • Workflow automation
  • SQL assistants
  • Coding assistants

AI-Infrastructure/2-5-LangChain
Let's work together
+49 176-2019-2523
hiteshkrsahu@gmail.com
WhatsApp
Skype
Munich 🥨, Germany 🇩🇪, EU
Playstore
Hitesh Sahu's apps on Google Play Store
Need Help?
Let's Connect
Navigation
  Home/About
  Skills
  Work/Projects
  Lab/Experiments
  Contribution
  Awards
  Art/Sketches
  Thoughts
  Contact
Links
  Sitemap
  Legal Notice
  Privacy Policy

Made with

NextJS logo

NextJS by

hitesh Sahu

| © 2026 All rights reserved.