Video summary
Conditional Workflows in LangGraph | Agentic AI using LangGraph | Video 7 | CampusX
Main summary
Key takeaways
Summary
The video explains how to build conditional workflows in LangGraph. Unlike a sequential workflow, which runs tasks one after another, or a parallel workflow, which executes multiple branches at once, a conditional workflow chooses one branch based on a condition—similar to an if/else statement.
The presenter demonstrates the idea with two examples: a quadratic-equation solver and an LLM-based customer-support workflow.
Main Concepts
- Sequential workflow: Tasks run one after another in a fixed order.
- Parallel workflow: Multiple branches run simultaneously, and their results can be combined later.
- Conditional workflow: The workflow evaluates a condition and follows only the matching branch. There can be more than two possible branches.
- In LangGraph, a routing function checks the state and returns the name of the next node. The graph uses conditional edges to route execution accordingly.
Example 1: Quadratic-Equation Workflow
The first example solves an equation of the form (ax^2 + bx + c = 0).
-
Define the workflow state
- Store the coefficients
a,b, andc. - Store the formatted equation.
- Store the discriminant.
- Store the result as a string.
- Store the coefficients
-
Create the initial nodes
- Show Equation formats the equation using the supplied coefficients.
- Calculate Discriminant computes (D = b^2 - 4ac).
-
Create result nodes
-
Real roots: If (D > 0), calculate two distinct real roots: [ \frac{-b+\sqrt D}{2a} \quad\text{and}\quad \frac{-b-\sqrt D}{2a}. ]
-
Repeated root: If (D = 0), calculate the single repeated root, (-b/(2a)).
- No real roots: If (D < 0), report that there are no real roots.
-
-
Add conditional routing
- A routing function checks the discriminant and returns the appropriate result-node name.
- Conditional edges route the graph to that node.
- Each result node then connects to the end of the workflow.
The key lesson is that the workflow’s branching logic is handled by a function that selects the next node, rather than by connecting every branch as an ordinary edge.
Example 2: LLM-Based Review-Response Workflow
The second example handles customer reviews and generates an appropriate response.
-
Define the workflow state
- Review text.
- Sentiment (
positiveornegative). - A diagnosis dictionary for negative reviews.
- The final response.
-
Classify sentiment
- An LLM analyzes the review.
- A structured-output schema restricts the result to
positiveornegative.
-
Route by sentiment
- A routing function checks the sentiment.
- Positive reviews go to Positive Response.
- Negative reviews go to Run Diagnosis.
-
Handle positive reviews
- An LLM writes a warm thank-you response.
- The prompt asks it to invite the customer to leave feedback on the website.
-
Diagnose negative reviews
- A second structured-output schema asks the LLM to identify:
- Issue type, such as UX, performance, bug, support, or other.
- Tone, such as the user’s emotional tone.
- Urgency, classified as low, medium, or high.
- The diagnosis is saved in the workflow state.
- A second structured-output schema asks the LLM to identify:
-
Respond to negative reviews
- An LLM uses the issue type, tone, and urgency to create an empathetic, helpful resolution message.
- The positive and negative response paths both connect to the workflow’s end.
The demonstration shows that structured outputs can make LLM results easier to use in workflow conditions and later steps.
Overall Lessons
- Conditional routing is a core workflow pattern in LangGraph, especially for more complex applications.
- A conditional workflow needs a clear state, nodes, a routing function, and conditional edges.
- The routing function determines which node runs next; only the selected branch is executed.
- Combining structured LLM outputs with conditional routing lets a workflow adapt its actions to the content of a user’s input.
Speakers and Sources Featured
- Nish — presenter and narrator.
- NCERT textbook — referenced for the quadratic-equation rules and root formulas.
- OpenAI GPT-4o Mini — named as the model used in the LLM-based workflow demonstration.
Rate this summary
Your feedback will help improve summaries.
Improve this summary
Reprocess with a stronger model when the summary feels incomplete or inaccurate.
Translate summary in another language
Ask questions to this video
Chat for follow-up questions, clarifications, and source-backed answers.