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 Model Node

00:00 Next, you’re digging into the brain of the agent into the model. So on line 112, you decide to use OpenAI’s gpt-5.4-nano model, and you make it aware of the tools that it has at its disposal, and importantly, their docstrings, by using the .bind_tools() method.

00:22 The input parameter tools is the list of Python function references that you defined in a previous lesson. On line 117, then, you define the model node.

00:34 As a node in your agent state graph, the model node needs access to the agent’s state, right? So the MessagesState is passed in here as input parameter.

00:44 Line 117 also describes the dictionary that this node is expected to return. So keys are to be strings, and the values are to be lists of AIMessage objects.

00:56 Line 119, that’s where you access the messages from the state, and you pass those to your LLM model on line 120 via the .invoke() method.

01:08 Now, this .invoke() method returns those AIMessage objects. On line 121, then, you return a dictionary as required with a key messages, which is a string, and as values, a list of AIMessage objects.

01:24 Now you might be thinking there’s something missing here, Steven, because you said that nodes append their output messages to the state. There is no line of code here that does that.

01:34 And you would, of course, be correct, but rest assured, LangGraph does that for you automatically. Well spotted, though. So that’s you done with the nodes. In the next lesson, you’ll cover the routing function for your conditional edges.

Become a Member to join the conversation.