Get startedGet started for free

Create the graph workflow for multiple tools

Your building blocks for creating your chatbot graph are now ready! You'll put all of your nodes together into a single workflow using edges to manage the connections between them. To get started, your graph workflow has already been set up for you with MessagesState and the StateGraph() to track the chatbot's message updates. The display() function to render your graph as a LangGraph diagram has also been set up and the MemorySaver has been imported for you.

from langgraph.graph import StateGraph
from langgraph.checkpoint.memory import MemorySaver

workflow = StateGraph(MessagesState)

This exercise is part of the course

Designing Agentic Systems with LangChain

View Course

Exercise instructions

  • Add call_model as a node using the label "chatbot" and add tool_node with the label "tools".
  • Define an edge connecting the START node to the "chatbot" node.
  • Add conditional edges from the "chatbot" node to the "tools" and END nodes using should_continue, before connecting the "tools" node back to the "chatbot" node.
  • Create a MemorySaver() instance and compile the workflow into an application with the memory checkpointer.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Add nodes for chatbot and tools
workflow.add_node("____", ____)
workflow.add_node("____", ____)

# Define an edge connecting START to the chatbot
workflow.add_edge(____, "____")

# Define conditional edges and route "tools" back to "chatbot"
workflow.add_conditional_edges("____", ____, ["____", ____])
workflow.add_edge("____", "____")

# Set up memory and compile the workflow
memory = ____()
app = workflow.____(checkpointer=____)

display(Image(app.get_graph().draw_mermaid_png()))
Edit and Run Code