LangGraph Agents - Controllability - Sub-graphs
Skills:
Agent Foundations80%Tool Use & Function Calling70%Multi-Agent Systems60%Autonomous Workflows50%
Key Takeaways
LangGraph Agents utilize subgraphs for controllability, parallelization, and state management, integrating with LSmith for advanced applications and analysis. The video demonstrates how to define and manage subgraphs, inherit state, and process logs for failure analysis.
Full Transcript
hey this is Lance from Lang chain we've been doing a few videos about more advanced Lang graph Concepts and I want to talk today about subgraphs so subgraphs are a way to break up complex kind of graphs into smaller substeps and the key point is that each of those kind of substeps or subgraphs can have their own uh their own state so let's take an example of like let's say you had a multi-agent uh graph and each of your agents you want to have independent state you want to isolate that State per agent this is a great kind of example or use case for subgraphs so here's like a toy example let's say I had like a node that branched out into two different subgraphs and you can see each subgraph P basically inherits state from that parent node but it also has its own state so subgraph one has its own little hello world State the and two has fizzbuzz right that's the overall idea um this Falls within the general kind of theme of controllability we talked about parallelization we talked about map reduce subgraphs are kind of another mechanism of controllability when you're building graphs so let's kind of cover a toy example and I want to actually talk through kind of this information transfer um between the different components and in slightly more explicit terms so let's say I had this toy uh graph that processed logs okay these could be logs from some kind of observability system right and I have some entry graph now in this entry graph I grabb those logs and I save it to some State that's called docs okay and I have two subgraphs one that will summarize what's in those logs and the other that will provide some kind of failure analysis like if there's any mistakes in the logs it'll it'll summarize them right now what's nice is these subgraphs are basically nodes within my entry graph or in My overall what we might call the parent graph and they can inherit the state from the parent so this is a key point when I was kind of covering this initially confused me a little bit so basically I Define my parent graph which is this entry graph these summarization and failure node and failure analysis are subgraphs that are kind of defined as nodes within the parent and they can inherit state from the parent and so all I need to do is in each of these subgraphs in their kind of subgraph state I just Define docs which is automatically kind of inherited from the parent so that's really convenient so I can work with it and that's how I can transfer information from my kind of parent graph in this case the entry graph into each of my subgraph so each of those have access to docs they can do their own thing on them each of them have their kind of own independent like States in here summary failures right those are states that are kind of private to the subgraph and they're going to write out a summary report and a failure report now what's nice is all I need to do is simply specify these in my parent state that then they will be accessible in in my paragraph when I finish so basically uh you know when I kind of set this up up front I say okay here's the things I'm going to want to have access to from my subgraphs I make those a part of my kind of overall parent graph State and by the end once these subgraphs run it'll be present and populated so I can just access it so that's really it so when I finish I'm going to access the summary report and the failure report so that's really it now let's actually see this in code so I'll copy over this to a to a fresh notebook and what you're going to see is so this is just kind of we're defining the structure of our logs this is just you know a toy example here so let's imagine these are logs from some kind of question answer system they contain questions docs answers and grades and feedback right so here's my failure analysis subgraph let's just Define those first so it's going to have docs like we kind of showed before it'll have failures it'll have some failure analysis summary right and it has some nodes and this can be whatever I want get failures generate the sum this is just a placeholder of course right I My Graph Builder super simple it just basically takes in that state it adds the nodes it creates an entry point Fin and uh adds one Edge finishes summarization subgraph is similar to find my state again docs is inherited from the parent it has some kind of independent uh or kind of like private state within the subgraph and then it has this report okay so there we go we can just Define those two subgraphs and we have builders for each of those so that's really all we need done there now uh what we're going to do is we're just going to kind of copy over here so here's some like dummy logs I'm going to process now here's my parent or entry graph now you can see this docs let's go back to our kind of diagram here this docs is what I'm going to pass through to the subgraph so docs is basically defined in My overall graph State and you can see it was also specified in the subgraph states here and right here so this Doc is what I'm going to transfer through to the subgraphs that's cool now we're going to see here and I comment it right right here failure and failure fa summary and Report are going to be populated or generated by our subgraphs and they're going to be basically it will be present or available to us in this overall parent graph State once the subg graph's run so basically all I'm doing here is I'm basically adding placeholder State variables for what I want to get back from my subgraphs that's really it and we can go back and look so failure failure analysis summary is defined um right up here in my failure analysis subgraph and then the report is defined in my summarization subgraph so that's it and this is just some other little things now let's actually just kind of run this and we can see it so this is kind of cool I when I see the graph laid out I can see everything so here's kind of my parent I'm converting the logs to docs and you know this could be some operation where you go from raw locks it's like kind of structured uh kind of structured logs person some schema you then route those to each of your subgraphs those subgraphs run and then you end and when you end in your overall kind of parent State you're going to have access to the failure analysis summary and the report that's exactly what you want uh and so we can go all the way down and we can just go ahead and run this and I'll just you know send in some dummy logs and here we go so you can see we basically kind of show the state as it run and what we can see here is um our failure analysis summary and the report are returned when we invoke the graph because they're present in our overall parent state right here so each subgraphs ran produced the failure analysis summary in the report which is present to us um in the the final uh state of the parent once everything runs and so that's really it subgraphs are really convenient often you're building a more complex systems that you want to kind of encapsulate different subprocesses with its own with their own State um this is obviously really useful and we see many many different teams do this uh when building kind of larger agentic systems and this is just a toy example showing you how everything fits together so I do want to interject here and just show quickly that Lang graph actually works really nicely with lsmith and for applications like this when I have different subgraphs it's actually really nice to be able to go to Lang Smith and for example to dig into what's happening with any subgraph so I've logged to my default project rlm within Langs Smith here's the trace we've been working on and so you can see convert logs to docs that's kind of our starting point if you look at our diagram so there we go and here are the two subgraphs so faal analysis question summarization so basically if I click on this convert logs to docs I can see the input and the output from this particular step so that's great and what I can do is I can basically open up the subgraph and I can see the input and output of the overall sub graph which is great and I can actually open that up I can look at the individual steps so get failures generate summary likewise with question summarization I can look at the individual steps um I can dig into each step I can look at the inputs and outputs and of course in the real in the kind of a realistic case these steps could involve kind of more involved calls which you may want to debug um of course I get useful information about kind of token usage in this case Zero tokens for this particular part of the graph uh zero tokens overall I don't make llm calls here but latency uh as well as token usage will be provided for you so again Lang Smith is very useful for auditing the graphs that you're running particular if you have a larger overall graph that incorporates multiple subgraphs
Original Description
For more complex systems, sub-graphs are a useful design principle. Sub-graphs allow you to create and manage different states in different parts of your graph. This allows you build things like multi-agent teams, where each team can track its own separate state.
Documentation:
https://langchain-ai.github.io/langgraph/how-tos/subgraph/
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from LangChain · LangChain · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Chat With Your Documents Using LangChain + JavaScript
LangChain
LangChain SQL Webinar
LangChain
LangChain "OpenAI functions" Webinar
LangChain
LangSmith Launch
LangChain
LangChain x Pinecone: Supercharging Llama-2 with RAG
LangChain
LangChain Expression Language
LangChain
Building LLM applications with LangChain with Lance
LangChain
Benchmarking Question/Answering Over CSV Data
LangChain
LangChain "RAG Evaluation" Webinar
LangChain
Fine-tuning in Your Voice Webinar
LangChain
Tabular Data Retrieval
LangChain
Building an LLM Application with Audio by AssemblyAI
LangChain
Superagent Deepdive Webinar
LangChain
Lessons from Deploying LLMs with LangSmith
LangChain
Shortwave Assistant Deepdive Webinar
LangChain
Cognitive Architectures for Language Agents
LangChain
Effectively Building with LLMs in the Browser with Jacob
LangChain
Data Privacy for LLMs
LangChain
"Theory of Mind" Webinar with Plastic Labs
LangChain
LangChain Templates
LangChain
Using Natural Language to Query Postgres with Jacob
LangChain
Building a Research Assistant from Scratch
LangChain
Benchmarking RAG over LangChain Docs
LangChain
Skeleton-of-Thought: Building a New Template from Scratch
LangChain
Benchmarking Methods for Semi-Structured RAG
LangChain
LangSmith Highlights: Getting Started
LangChain
LangSmith Highlights: Debugging
LangChain
LangSmith Highlights: Datasets
LangChain
LangSmith Highlights: Evaluation
LangChain
LangSmith Highlights: Human Annotation
LangChain
LangSmith Highlights: Monitoring
LangChain
LangSmith Highlights: Hub
LangChain
SQL Research Assistant
LangChain
Getting Started with Multi-Modal LLMs
LangChain
Build a Full Stack RAG App With TypeScript
LangChain
Auto-Prompt Builder (with Hosted LangServe)
LangChain
LangChain v0.1.0 Launch: Introduction
LangChain
LangChain v0.1.0 Launch: Observability
LangChain
LangChain v0.1.0 Launch: Integrations
LangChain
LangChain v0.1.0 Launch: Composability
LangChain
LangChain v0.1.0 Launch: Streaming
LangChain
LangChain v0.1.0 Launch: Output Parsing
LangChain
LangChain v0.1.0 Launch: Retrieval
LangChain
LangChain v0.1.0 Launch: Agents
LangChain
Build and Deploy a RAG app with Pinecone Serverless
LangChain
Hosted LangServe + LangChain Templates
LangChain
LangGraph: Intro
LangChain
LangGraph: Agent Executor
LangChain
LangGraph: Chat Agent Executor
LangChain
LangGraph: Human-in-the-Loop
LangChain
LangGraph: Dynamically Returning a Tool Output Directly
LangChain
LangGraph: Respond in a Specific Format
LangChain
LangGraph: Managing Agent Steps
LangChain
LangGraph: Force-Calling a Tool
LangChain
LangGraph: Multi-Agent Workflows
LangChain
Streaming Events: Introducing a new `stream_events` method
LangChain
Building a web RAG chatbot: using LangChain, Exa (prev. Metaphor), LangSmith, and Hosted Langserve
LangChain
OpenGPTs
LangChain
Open Source RAG with Nomic's New Embedding Model (and ChromaDB and Ollama)
LangChain
LangGraph: Persistence
LangChain
More on: Agent Foundations
View skill →Related Reads
📰
📰
📰
📰
AI Agents and Open-Source Bounties: Revolutionizing Software Development Through Collaboration
Dev.to AI
Gate Agent Evals by Severity, Not a Flat Pass-Rate
Dev.to AI
Beyond the chat window: Designing trustworthy AI assistants for public services
Medium · AI
What Is Vibe Video? The New Way to Create Films by Talking to AI
Medium · AI
🎓
Tutor Explanation
DeepCamp AI