← Table of Contents · Page 118 of 868

CONTROL STRUCTURES AND DECISION ROUTING

Part 2 of 9

DIRECTED GRAPHS OF NODES AND EDGES As agent logic grows, a long chain of if statements becomes hard to read. Engineers often draw the logic as a picture instead. The picture is a directed graph. A graph, in this sense, is not a chart with bars; it is a drawing of dots connected by arrows. Each dot is called a node and stands for a unit of work, such as "collect documents." Each arrow is called an edge and shows which node can run next. The word directed means each arrow points one way, from where you are to where you may go. Picture a subway map where trains only run in one direction on each line. You start at a station (a node), and each track segment (an edge) takes you to the next station. Some stations have more than one outgoing track, and the rider takes one depending on a condition. That is a conditional edge. Writing agent logic as a graph brings real benefits. It is easy to see the whole workflow at a glance. Each node can be tested by itself. You can prove that certain paths are impossible, for example that the "approve loan" node can only be reached after the "verify identity" node. You can pause and resume at any node, because the state records which node you are on, and this connects directly to Chapter 10. Many modern orchestration frameworks, the libraries that help coordinate agent workflows, are built around exactly this graph idea, and you will survey some of them in Part Twelve. A graph may also contain a cycle, meaning a path that leads back to an earlier node. The ReAct loop of Chapter 9 is itself a small cycle: think leads to act, act leads to observe, and observe leads back to think.
Advertisement
Read Aloud:
0:00 / 0:00