Join us and get access to thousands of tutorials and a community of expert Pythonistas.
This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.
Exploring the Notice Extraction State Graph
00:00 In this lesson, you’ll explore some interesting parts of the notice extraction state graph. There are three points I’d like to highlight. One, the state of this state graph is more complex than that of the agent.
00:14
That’s also the case for the conditional edges. And then thirdly, I’d like to show you an example of the use of a LangChain chain. In terms of code, please open the notice_extraction.py module in the graphs subfolder.
00:30
So on line 23, a blank workflow is defined as a state graph, as you saw for the agent, but now the state is not a MessagesState, but a GraphState.
00:42
And what is that? Well, GraphState is a class that is defined on line 12, and it inherits from TypedDict. Now a TypedDict is a base class that allows you to define a fixed schema where different keys can have different data types.
01:00
So GraphState holds all the variables that the notice extraction graph needs access to, such as notice_message, the email extract, escalation criteria, and so on.
01:10
And these are of different data types. You can see strings, Booleans, lists, and so on. Now you can see that this is a bit more elaborate than the MessagesState that the agent state graph was using.
01:24 The rest of the workflow is built up from line 128 onwards. Now that should look all quite familiar to you by now, except for maybe the conditional edges. As you can see on lines 139 to 142, or 147 to 150, the path map is now a dictionary as opposed to a list.
01:48 So this is how you would deal with a situation where the routing function doesn’t return exact node names. So the key of the dictionary is what the routing function returns, and the value of the dictionary is the node name to go to in that case.
02:05 Now, it turns out that here the routing function does actually return the exact node names, so you could have just used the list as before for the agent state graph.
02:15 But I wanted to quickly show you how to deal with a situation where that isn’t the case.
02:23
The last thing I wanted to show you is the LangChain example, so that starts on line 26. There are three chains being used as you saw earlier in the course, but you’ll only look at one of them, the NOTICE_PARSER_CHAIN, and that is used by the parse_notice_message node.
02:42
So line 26 is where you define that parse_notice_message node. On lines 31 and 32, this node reads the notice_message from the state and passes that to the .invoke() method of the NOTICE_PARSER_CHAIN.
02:59
The NOTICE_PARSER_CHAIN is a LangChain chain, and this is what I wanted to show you, and this is where the message is passed to the LLM as a prompt.
03:09 LangChain is outside of the scope of this course, but for completeness, I’ll walk you very briefly through that chain in the next lesson.
Become a Member to join the conversation.