Introducing Agents, Workflows, and State Graphs
00:00 In this lesson, you’ll learn about agents, workflows, and state graphs, and how these concepts come together for building your AI agent. So what is an AI agent?
00:12 Well, that is a system in which an AI model pursues a goal over multiple steps, and it will be choosing its own actions, and it will be using tools to interact with an environment, and it will be guided by feedback from the results.
00:28 Now, if you would draw a quick flowchart of how an agent operates, it could look something like this. So the process starts at the top, the agent uses a model to make decisions.
00:38 Now, if the model decides it needs a tool, it will tell the tools what it needs, and the tools will then send back to the model what the model needs. And when the model needs no more tools and it has done everything that it is supposed to do, the process ends.
00:53 So the dotted arrows here represent conditional flows, because whether to go to the tools or whether to go to the end depends on a decision that the model makes.
01:04 And the full arrows, they are not conditional, they always flow one way. Now, you can clearly see the cyclic nature of agents here, where the model and the tools are interacting constantly.
01:17 Now, you have your agent in workflow form, where does LangGraph come in? Well, LangGraph models workflows as state graphs, and the state in state graphs is crucial, so hold that thought for a moment.
01:31 But first, let me tell you a bit more about LangGraph. So LangGraph is a Python framework for building stateful, cyclic, and multi-agent applications powered by LLMs.
01:41 It represents an AI application as a graph, hence its name, where each application step is a node and the connection between steps are edges.
01:51 So two new concepts here for you, nodes and edges. It’s especially useful when modeling nonlinear processes, for example, with cycles and conditional branches, which is, of course, what agents need, as you have just seen.
02:09 So how do we get to a state graph? So far, you have created this high-level agent workflow. Now, to model this workflow as a state graph using LangGraph, all you need to do is use the state graph concepts of nodes and edges.
02:24 So if you now rename the purple boxes to model node and tools node and you refer to the arrows as edges, you have the layout of an AI agent state graph. Your AI agent state graph has a model node and a tools node.
02:40 It has normal edges, which are the full arrows. It has conditional edges, the dotted arrows, and a cycle between the model node and tools node. So that’s the nodes and the edges taken care of.
02:55 So coming back to the state in state graphs, what is so special about the state graph? Well, it remembers information across multiple steps or nodes and over time.
03:06 So instead of treating every step, every node as an isolated event, a stateful workflow passes a central memory object from one node to the next.
03:17 And that is your state. So the state is a central memory object. It holds all your variables, messages, or Boolean flags, and there is shared access.
03:27 So every node in your graph can read from this state, update it, and pass it along.
03:35 Okay, with the theory under your belt, let me help you set up your environment in the next lesson.
Become a Member to join the conversation.