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
inputs
message dictionary with the user'squery
ascontent
forHumanMessage
. - Stream
msg
andmetadata
from the chatbotapp
by iterating over the results using the.stream()
method incorporatinginputs
andconfig
. - Check if each
msg
hascontent
and is not aHumanMessage
, then print itscontent
withflush
set toTrue
for 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?")