1. Learn
  2. /
  3. Courses
  4. /
  5. Designing Agentic Systems with LangChain

Connected

Exercise

Queries and responses

The agent graph is set up so your chatbot is ready to run! Now you can define a function that allows the chatbot to answer queries using ChatGPT. This function will stream through the graph events in real-time and return the last message as a response to the user's query.

Instructions

100 XP
  • Define the stream_graph_updates() function to accept user_input as a string parameter for chatbot execution.
  • Apply the .stream() method to graph to stream events with user_input as a "user" message in "messages".
  • For each item in event.values(), retrieve and print the response using the "messages" key in item.
  • Pass user_query to the stream_graph_updates() function to test the chatbot.