AI Agents with LangGraph

Nov 12 2024 · Python 3.12, LangGraph 0.2.x, JupyterLab 4.2.4

Lesson 03: Building Complex AI Agents

Decision Making Demo

Episode complete

Play next episode

Next

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Heads up... You’re accessing parts of this content for free, with some sections shown as obfuscated text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

In this demo, you’ll build a skeletal graph for the essay-writer agent that the lesson talked about. You won’t use any LLMs this time. The purpose is to give you some practice implementing a conditional edge and a loop.

def writer(input):
  return "an essay"
revisions = 0

def reviser(input):
  global revisions
  revisions = revisions + 1
  print(f"revision number {revisions}")
  return input + " revisions"
def checker(input):
  if revisions >= 3:
    return "good"
  else:
    return "feedback"
from langgraph.graph import Graph, START, END

graph = Graph()

graph.add_node("writer", writer)
graph.add_node("reviser", reviser)
graph.add_node("checker", checker)
graph.add_edge(START, "writer")
graph.add_edge("writer", "checker")
graph.add_edge("reviser", "checker")
def check(input):
  if input == "good":
    return "pass"
  else:
    return "fail"
graph.add_conditional_edges(
  "checker",
  check,
  {
    "fail": "reviser",
    "pass": END
  }
)
app = graph.compile()
from IPython.display import Image, display

display(Image(app.get_graph().draw_mermaid_png()))
See forum comments
Cinema mode Download course materials from Github
Previous: Decision Making & AI Agent Architecture Next: Tools