Stanford Online

DSPy vs. LangGraph: AI Agent Frameworks Explained | Stanford CS329Z Lecture 5 with Michael Ryan

Published 2026-11-13 · Duration 1:17:14

Summary

This lecture provides a deep dive into modern AI agent frameworks, comparing DSPy and LangGraph for building complex, multi-stage AI systems. The core message is that engineering an AI system requires three pillars: the system itself, the data, and rigorous evaluation (evals). Frameworks like DSPy focus on optimizing prompt structures via signatures and modules, while LangGraph emphasizes robust orchestration using state machines (nodes, edges, and shared state). For production-grade systems, the lecture stresses the necessity of external tools for reliability (e.g., Temporal for durable execution) and observability (e.g., LangSmith, MLflow) to manage long-running, complex workflows.

Download summary

Key takeaways

  1. The Three Pillars of AI System Engineering 2:08

    Building an AI system requires not just the model (the system), but also high-quality data (training, rollouts, feedback) and defined evaluation metrics (e.g., pass rate, exact match).

  2. DSPy's Core Components 7:30

    DSPy structures agent development around three concepts: 'signatures' (defining strict input/output contracts for the LLM), 'modules' (composing logic like `dspy.Predict` or `dspy.ChainOfThought`), and 'optimizers' (automatically improving prompts and weights using labeled data and metrics).

  3. LangGraph for Robust Orchestration 19:10

    LangGraph models workflows as state machines, using a shared state, defined 'nodes' (functions that read/write to the state), and 'edges' (which define the control flow, including conditional routing). This structure is ideal for complex, stateful processes.

  4. Engineering for Production Reliability 30:00

    For long-running agents, reliability is key. Tools like Temporal ensure durable execution by managing activities and retries, while observability tools (LangSmith, MLflow) are crucial for tracing model calls, state changes, and debugging failures.

More digests on AI Agent Frameworks

Technical details

  • DSPy Framework 360s

    DSPy uses 'signatures' to strictly define LLM inputs and outputs, enabling structured output (e.g., enforcing a `float` confidence score or a `date` type). Modules allow composing logic (e.g., `dspy.Predict`, `dspy.ChainOfThought`). The `dspy.Optimizer` improves the underlying prompt and weights using labeled data and a defined metric.

  • LangGraph Framework 1150s

    LangGraph defines workflows using a shared state, nodes, and edges. Nodes are functions that read from and write to the state. Conditional edges allow the graph to dynamically route execution based on the current state, making it suitable for complex state machines.

  • Agent Architecture (ReAct) 700s

    The ReAct architecture is an agent pattern where the LLM decides its next action (Thought $ ightarrow$ Action $ ightarrow$ Observation). Both DSPy and LangGraph can implement this pattern, allowing the model to use external tools (e.g., a calendar API SDK).

  • Orchestration and Observability 1800s

    Temporal provides durable execution, allowing workflows to resume automatically after failures. Observability tools like LangSmith and LangFuse track inputs, outputs, latency, and execution history, which is critical for debugging long-running agent processes.

Mentioned resources

Channel & topics

Watch on YouTube · Back to latest

This independent, AI-assisted summary is provided for commentary and informational purposes. It may contain errors or omit important context. Please watch the original video for the creator's complete presentation. Video, thumbnail, and related copyrights belong to their respective owners.