1. Learn
  2. /
  3. Courses
  4. /
  5. Designing Agentic Systems with LangChain

Connected

Exercise

Adding nodes and edges

Now that your StateGraph() is ready, it's time to add your chatbot's nodes to the graph! The pre-built START and END nodes are directly imported from LangGraph, so you'll have just one chatbot node to create. You'll also define the edges that determine the direction of your chatbot's conversation, from start to finish. Once your nodes and edges are added, you'll compile the graph to get it ready to run with a query.

Instructions

100 XP
  • Define the chatbot function by using the llm.invoke() method on the current "messages" in state and return its response.
  • Use .add_node() to add a node named "chatbot" to the graph that references the chatbot function.
  • Connect the START node to the "chatbot" node and "chatbot" to the END node using .add_edge() to define the edges for the conversation.
  • Compile the graph using .compile() to prepare it for execution.