IniziaInizia gratis

Create the graph workflow for multiple tools

Your building blocks for creating your chatbot graph are now ready! You'll put all of your nodes together into a single workflow using edges to manage the connections between them. To get started, your graph workflow has already been set up for you with MessagesState and the StateGraph() to track the chatbot's message updates. The display() function to render your graph as a LangGraph diagram has also been set up and the MemorySaver has been imported for you.

from langgraph.graph import StateGraph
from langgraph.checkpoint.memory import MemorySaver

workflow = StateGraph(MessagesState)

Questo esercizio fa parte del corso

Designing Agentic Systems with LangChain

Visualizza il corso

Istruzioni dell'esercizio

  • Add call_model as a node using the label "chatbot" and add tool_node with the label "tools".
  • Define an edge connecting the START node to the "chatbot" node.
  • Add conditional edges from the "chatbot" node to the "tools" and END nodes using should_continue, before connecting the "tools" node back to the "chatbot" node.
  • Create a MemorySaver() instance and compile the workflow into an application with the memory checkpointer.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# Add nodes for chatbot and tools
workflow.add_node("____", ____)
workflow.add_node("____", ____)

# Define an edge connecting START to the chatbot
workflow.add_edge(____, "____")

# Define conditional edges and route "tools" back to "chatbot"
workflow.add_conditional_edges("____", ____, ["____", ____])
workflow.add_edge("____", "____")

# Set up memory and compile the workflow
memory = ____()
app = workflow.____(checkpointer=____)

try:
    display(Image(graph.get_graph().draw_mermaid_png()))

except Exception:
    print("Plot generation failed... falling back to cached asset.")
    display_fallback()
Modifica ed esegui il codice