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
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("researcher", "author")
workflow.add_edge("author", "reviewer")
# Add conditional edges from blogger
workflow.add_conditional_edges(
"reviewer",
lambda state: "author" if state.get("review_result") == rejected else "blogger"
{
"author": "author",
"END": END
}
app = workflow.compile()
That’s it. All that’s left is to take it out for a spin.





































