Skip to main content

馃憪 Build and execute the graph

Now that we have defined the nodes and edges of the graph, let's put the graph together and execute it to ensure that our agent is working as expected.

Fill in any <CODE_BLOCK_N> placeholders and run the cells under the Step 10: Build the graph and Step 11: Execute the graph sections in the notebook to build and execute the graph.

The answers for code blocks in this section are as follows:

CODE_BLOCK_17

Answer
graph.add_node("agent", agent)

CODE_BLOCK_18

Answer
graph.add_node("tools", tool_node)

CODE_BLOCK_19

Answer
graph.add_edge(START, "agent")

CODE_BLOCK_20

Answer
graph.add_edge("tools", "agent")

CODE_BLOCK_21

Answer
graph.add_conditional_edges(
"agent",
route_tools,
{"tools": "tools", END: END},
)
caution

Upon executing the graph, if you see the agent get stuck in an infinite tool-calling loop, play around with the prompt in Step 7 and run the cells that follow until you initialize the llm_with_tools variable. If this doesn't work, consider this a lesson in working with non-deterministic ML models. 馃檪