Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Coding the Tool Node and Tools

00:00 This lesson covers the tool node and the available tools. So on line 110, you’ll find the tool node, which uses the LangGraph pre-built ToolNode object.

00:11 Now, that shouldn’t surprise you because from the previous lessons, you’ve learned that the tool node is a pre-built execution engine. Now, the tool node takes the list of tools as an input parameter, and that is defined on line 104.

00:26 It holds references to those Python functions that are in fact your tools. Now, if you scroll up, you can find those Python functions, those tools on lines 14, 30, 47, and 76.

00:40 Now, the first thing to notice is that all four have been decorated with the @tool decorator. Now, a key functionality of the @tool decorator is to pass the tool’s docstring to your agent’s LLM.

00:56 It’s therefore imperative that you write accurate and informative docstrings, as is the case for these four functions. Now, three of these functions you’re not going to spend any time on right now because they are either just simulations using the sleep() functionality or just return a hard-coded string, which isn’t terribly interesting.

01:18 But you will have a look at the extract_notice_data on line 47. The aim of this tool is to extract structured information from an email, and the excellent docstring on line 50 gives you and, crucially, the agent’s LLM a lot more detail.

01:38 Line 49 suggests this tool is expected to return a NoticeEmailExtract. Now, this is an object that you will define later in the course when exploring a LangChain chain.

01:49 But for now, just know that it holds structured output from the emails. To extract structured information from emails, this tool invokes another state graph called notice extraction graph.

02:02 And you can see this on line 71. This state graph uses a more complex type of state than your agent’s MessagesState. And on line 62, you create that initial state and you pass that into the .invoke() method of the notice extraction graph, where it can be updated as needed.

02:24 As you will see later in the course, the results returned on line 72, all the way down here at the bottom of the screen, are indeed a NoticeEmailExtract object, as was suggested on line 49 up here.

02:40 So that’s you done exploring the tool node and one of the tools. You’ll come back to one of the tools in more detail later when you peel back another layer of the onion.

02:50 But for now, in the next lesson, you will cover the model node or the agent node.

Become a Member to join the conversation.