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

Connected

Exercise

Graph and agent states

You've been commissioned to create a basic chatbot that can answer questions within a high school education app. The school would like you to use a version of ChatGPT from OpenAI as its LLM. You've decided you can efficiently manage this task using LangGraph to build a chatbot agent using nodes. First, you'll define an agent State() to store the agent's data, and set up a StateGraph() object to manage the agent's workflow.

The required modules have already been imported for this exercise and those that will follow:

from langchain_openai import ChatOpenAI
from typing import Annotated
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages

Instructions

100 XP
  • Set up the llm using ChatOpenAI() and the model "gpt-4o-mini".
  • Define the State class using TypedDict to manage the chatbot's data.
  • Specify messages as an Annotated list using add_messages.
  • Initialize a StateGraph instance with State to structure the chatbot's workflow.