transcribe

LangGraph Agents - Human-In-The-Loop - User Feedback

LangChain · 5m · transcribed 15d ago
More from LangChain Business
𝕏 Share ▶ YouTube 📥 PDF 🤖 .md

Section Insights

# 0:00

Introduction to User Input in Lang Graph

What are the advanced features of Lang graph related to user input?

Lance introduces advanced features of Lang graph that allow for waiting for user input at specific points in a graph, enhancing human-in-the-loop capabilities.

  • Lang graph can pause execution to gather user feedback.
  • User input can be integrated into the graph state.
  • This feature builds on existing breakpoints functionality.
# 1:11

Understanding Checkpoints and Threads

How do checkpoints and threads function in Lang graph?

Checkpoints save the state of the graph at each step, which are then rolled up into a thread, allowing for a persistent state trajectory that can be referenced later.

  • Checkpoints capture the graph's state at specific moments.
  • Threads provide a way to return to a previous state in the graph.
  • This mechanism is useful for both breakpoints and user input scenarios.
# 2:22

Implementing a Breakpoint for User Feedback

How is a breakpoint implemented to gather user feedback?

A breakpoint is set before the human feedback node, allowing the graph to pause and gather user input before proceeding.

  • Breakpoints enable controlled pauses in graph execution.
  • User feedback can be collected seamlessly during graph execution.
  • This method allows for dynamic interaction with users.
# 3:34

Updating Graph State with User Feedback

How is user feedback integrated into the graph's state?

User feedback is inserted directly into the graph's state, allowing the graph to continue processing with updated information.

  • User feedback can be easily integrated as a node in the graph.
  • The graph state is updated with user input for subsequent steps.
  • This process enhances the interactivity of the graph.
# 4:45

Continuing Graph Execution with Threads

How does the thread facilitate the continuation of the graph after user input?

The thread retains all prior information, allowing the graph to resume execution from where it left off without needing to pass additional data.

  • Threads simplify the process of resuming graph execution.
  • User feedback is seamlessly integrated into the workflow.
  • This approach is beneficial for interactive applications requiring user input.

Transcript

0:01 hey this is Lance from Lang chain I want to talk about some of the more advanced Lang graph features focusing here on waiting for user input so sometimes we have a graph and at a certain point in our graph we want explicitly get feedback from a user this could be clarifying questions in the case of like a chatbot or an assistant but the point is we want to extract this information from the user at very particular points in our graph and add

0:25 it to our graph state so that's kind of the motivation now this sits within a broader set of human the loop kind capabilities within Lang graph we already did a video on break points which basically allow you to to basically stop execution of your graph at a certain node and this ability to wait for us your input build on top of the idea of break points now two of the important dependencies just like with breakpoints for this idea of waiting for user input

0:53 are checkpoints and threads so really in simple terms What's Happening Here is that as I run my graph every graph step can be saved I.E the state of the graph and the next nodes travel to in the graph can be saved by a checkpoint ter as a checkpoint so you can imagine your graph is going along at every step you're saving the checkpoint those checkpoints are then rolled up into what we call a thread and this thread is

1:19 basically a kind of a persistent State trajectory of your graph which you can reference at a later point in time so for example if your graph is running you hit a break break point and you stop it you have a thread that allows you to return to where your graph stopped and proceed so this is obviously useful in the case of a breakpoint where you're like waiting for human human approval and it's useful here if you're

1:43 actually waiting for user input in the case of like actual clarifying text so let's actually show this with some code I'll copy this over so here's a really simple graph our state just contains an input and a user feedback key we have three steps we have step one we have a step that collects our user feedback called human feedback and we have step three we've added these and it's a really simple

2:14 flow just as shown here now you can see I've added a checkpoint her we just talked about why that's important and I've also added this Interruption I.E this is a breakpoint I'm going to break point before my human feedback node so again what's going to happen is I'm going to go ahead and ceed until I hit human feedback and then I'm going to break now let's show this in action copy this over cool so here we go we pass our input we

2:48 create a thread we invoke our graph so our graph proceeds and we go ahead and hit step one and now before we hit human feedback we stop and then here's what our state is at this point in time our state is simply hello world now what I'm going to do is we're going to copy over here so right here this is just an example where I'm going to gather feedback from the

3:19 user and this is the Crux of it what I'm going to do is I'm just going to call this graph update state I'm going to pass that user input in to this update under the key user feedback so remember our graph had two keys input in user feedback so I can insert that user feedback directly here that's it nice and easy and here's what's kind of cool I can actually insert this as a node so it's as if that human feedback node in

3:49 my graph is running and I'm just populating it with feedback gathered from my user so if you look at my flow here here's the user feedback node I'm just going to run this node and Plum in the feedback I get from the user and that's what's going to happen right here so let's go ahead and do this let's say go ahead to step three cool and there we go so look at my state after the update is hello world and user

4:19 feedback go ahead to state to step three so my State's been updated with that user feedback which I've plumbed in and now you can see gra this graph. getet state next tells me what's the next node I want to go to well what we've done is we've already run that human feedback node right here and so the next St My Graph wants to go to is that third step so there we go and now all I need to do

4:47 because I have a thread that's gathered all this information all I need to do is invoke my graph with that thread I don't have to pass anything because it knows where to pick up because of that thread and it just goes to step three so that's really it very simple and if you pop all the way back up all we've done is we set up a graph we set up a node called human feedback which we're going to collect

5:06 user feedback G and insert it into our state and all we need to do is very simply set a breakpoint before that node where we stop before we hit this node and then we just manually call this graph update State we pass in the feedback here that we get from the user and we run that as a node human feedback so it's basically as if this node is running we update our state accordingly which we show here

5:30 and then we move forward to step three because the thread saves all the prior information so we're able to pick up where we left off and we can proceed forward so this is very generally useful and in particular if you have graphs where you want to kind of encode places where you can ask clarifying questions or gather more user input along your control flow this kind of approach of asking for user feedback directly as a node in your graph is extremely useful

5:54 thanks

Summary

Lance from LangChain discusses advanced features of LangGraph, particularly focusing on how to wait for user input within a graph. This capability allows for the collection of user feedback at specific points in the graph, enhancing the interactivity of applications like chatbots.

- The ability to wait for user input builds on the concept of breakpoints, allowing execution to pause for feedback.
- Checkpoints and threads are essential for saving the state of the graph at each step, enabling a return to that state later.
- A thread represents a persistent state trajectory of the graph, allowing users to resume from where they left off.
- The process involves setting up a graph with nodes for user input and feedback, and using breakpoints to pause before collecting feedback.
- User feedback can be directly inserted into the graph's state, making it feel as if the feedback node is actively running.
- This method is particularly useful for applications that require clarifying questions or additional user input during execution.
- The overall approach enhances user interaction and control flow within the graph structure.

Questions Answered

What are the advanced features of Lang graph related to user input?

Lance introduces advanced features of Lang graph that allow for waiting for user input at specific points in a graph, enhancing human-in-the-loop capabilities.

How do checkpoints and threads function in Lang graph?

Checkpoints save the state of the graph at each step, which are then rolled up into a thread, allowing for a persistent state trajectory that can be referenced later.

How is a breakpoint implemented to gather user feedback?

A breakpoint is set before the human feedback node, allowing the graph to pause and gather user input before proceeding.

How is user feedback integrated into the graph's state?

User feedback is inserted directly into the graph's state, allowing the graph to continue processing with updated information.

How does the thread facilitate the continuation of the graph after user input?

The thread retains all prior information, allowing the graph to resume execution from where it left off without needing to pass additional data.

© transcribe · For agents Built with care and craft by Gokul Rajaram