BaşlayınÜcretsiz Başlayın

Using graph memory for conversation

Now that your chatbot has access to memory, you can stream its responses to follow up questions. Note that your follow up questions will need no extra context as the chatbot can access the full conversation stored in its memory. The questions have already been set up for you.

Bu egzersiz

Designing Agentic Systems with LangChain

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Create a config dictionary with "configurable", containing "thread_id" set to "single_session_memory".
  • Loop through each graph event, applying the .stream() method to graph, passing a dictionary with "messages" containing the user_input labeled "user" and the config dictionary.
  • Loop through event.values() using value and print "Agent:" followed by "messages" if it exists in value and is not empty.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Set up a streaming function for a single user
def stream_memory_responses(user_input: str):
    ____ = {"____": {"____": "____"}}
    
    # Stream the events in the graph
    for ____ in graph.____({"messages": [("user", ____)]}, ____):
        
        # Return the agent's last response
        for ____ in event.____():
            if "messages" in ____ and value["____"]:
                print("Agent:", value["messages"])

stream_memory_responses("Tell me about the Eiffel Tower.")
stream_memory_responses("Who built it?")
Kodu Düzenle ve Çalıştır