Configure outputs for multiple tools
Your chatbot's graph is ready to go! Now you can test how the chatbot works with different queries that should require different tools. To manage your chatbot's messages, the following modules have already been imported and your chatbot's config parameters have been set for one session.
from langchain_core.messages import AIMessage, HumanMessage
config = {"configurable": {"thread_id": "1"}}
This exercise is part of the course
Designing Agentic Systems with LangChain
Exercise instructions
- Create an
inputsmessage dictionary with the user'squeryascontentforHumanMessage. - Stream
msgandmetadatafrom the chatbotappby iterating over the results using the.stream()method incorporatinginputsandconfig. - Check if each
msghascontentand is not aHumanMessage, then print itscontentwithflushset toTruefor immediate output printing. - Test the chatbot using
multi_tool_output()with queries requiring different tools.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create input message with the user's query
def multi_tool_output(____):
inputs = {"messages": [____(____=____)]}
# Stream messages and metadata from the chatbot application
for ____, ____ in app.____(____, ____, stream_mode="messages"):
# Check if the message has content and is not from a human
if ____.____ and not isinstance(____, ____):
print(____.____, end="", flush=____)
print("\n")
# Call the chatbot with different tools
____("Is `may a moody baby doom a yam` a palindrome?")
____("What happened on 20th July, 1969?")