Foundations: LangChain and LangGraph

LangChain Overview

LangChain is "the platform for reliable agents" - a framework for building applications powered by Large Language Models through a standard interface for models, embeddings, vector stores, and more [1].

Core Value Propositions:

  • Real-time data augmentation: Connect LLMs to diverse data sources and external systems
  • Model interoperability: Swap models easily as the industry evolves
  • Rapid prototyping: Build and iterate quickly with modular, component-based architecture
  • Production-ready features: Built-in support for monitoring, evaluation, and debugging through LangSmith

Installation:

pip install langchain

Core Architecture Components

LangChain's architecture is designed to be modular and extensible [2]:

ComponentDescription
ModelsStandard interface for interacting with various LLMs (OpenAI, Anthropic, Hugging Face, etc.)
ChainsSequences of calls to LLMs or other utilities that can be composed together
LCELLangChain Expression Language - declarative way to compose chains with streaming, batching, and async support
AgentsSystems that use LLMs to decide which actions to take
ToolsFunctions that agents can use to interact with the world

LangGraph: Stateful Agent Orchestration

LangGraph extends LangChain with the ability to coordinate multiple chains across multiple steps of computation in a cyclical manner [3]. It is specifically designed for building agent-like applications where control flow is not a simple linear sequence.

Key Features:

  1. Stateful, Long-Running Execution: Applications can run for extended periods, maintaining state and automatically resuming from where they left off
  2. Human-in-the-Loop: Seamless incorporation of human oversight into agentic workflows
  3. Comprehensive Memory: Both short-term working memory and long-term persistent memory across sessions
  4. Debugging with LangSmith: Deep visibility into agent behavior through visualization and tracing tools

State Graph Architecture

LangGraph represents workflows as graphs where:

  • State: Represented by a State object that accumulates information
  • Nodes: Functions that update the state
  • Edges: Control flow determining which node executes next

Integration Patterns

LangGraph supports several common workflow patterns [4]:

PatternDescriptionUse Case
Prompt ChainingSequential LLM calls where each processes the previous outputTasks broken into verifiable steps
ParallelizationMultiple LLM calls executed simultaneouslyIndependent subtasks, confidence checking
RoutingInput processing and direction to context-specific tasksSpecialized flows for complex tasks
Orchestrator-WorkerCentral orchestrator coordinates multiple workersTask planning and delegation
Evaluator-OptimizerEvaluator assesses output, optimizer improves generatorHigh-quality, iterative refinement

Code Example

# Basic LangChain Agent Example
# Source: LangChain Documentation
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="claude-sonnet-4-5-20250929",
    tools=[get_weather],
    system_prompt="You are a helpful assistant",
)

# Run the agent
agent.invoke(
    {"messages": [{"role": "user", "content": "what is the weather in sf"}]}
)

References

  1. LangChain GitHub Repository
  2. LangChain Documentation
  3. LangGraph GitHub Repository
  4. LangGraph Workflows and Agents