Before you start work on this assignment you will need to install the langgraph package. To do this, run the following commands in a terminal pane.
conda activate agents pip install langgraph
For this assignment and the next we will pretend that we are setting up a web site for comedians. As part of the sign-up process for the site we will ask users to write a joke. We will be using an LLM to evaluate the quality of the joke, and if the joke is not good enough we will ask the user to keep trying until they can produce a decent joke.
To implement the joke evaluation logic we will be using langgraph, since langgraph makes it relatively easy to set up logical structures featuring loops and decisions.
Here is the graph we will be using for our application.

Here is what the nodes in this graph will do.
Use the following dictionary for your graph's state:
class JokeState(TypedDict):
joke: str
classification: Optional[str]
rewrite: Optional[str]
Here is how to write the function for the prompt node:
def prompt_for_joke(state: JokeState) -> JokeState:
state['joke'] = input("Why did the chicken cross the road? ")
return state