In part 4 of this series we created our final two agents. In this final part of the series we’ll review the workflow that we create with the StateGraph class of LangGraph.
In the following code we pass the ResearchState object to StateGraph and create a node for each agent and edges that represent transitions between the nodes. There is one conditional edge: if the reviewer rejects the draft, it goes back to the author
from langgraph.graph import StateGraph, END
workflow = StateGraph(ResearchState)
workflow.add_node("blogger", blogger_node)
workflow.add_node("researcher", research_node)
workflow.add_node("author", author_node)
workflow.add_node("reviewer", reviewer_node)
workflow.set_entry_point("blogger")
workflow.add_edge("blogger", "researcher")
workflow.add_edge("researcher", "author")
workflow.add_edge("author", "reviewer")
workflow.add_conditional_edges(
"reviewer",
lambda state: "author" if state.get("review_result") == "rejected" else "END",
{
"author": "author",
"END": END
}
)
# Compile the graph
app = workflow.compile()
The conditional edge says, “Start with reviewer. Now examine the state. If the review_result is rejected, go to the author; otherwise, go to END. Finally, the dictionary identifies what each node is.
That’s it. All that’s left is to take it out for a spin.





































