Get startedGet started for free

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

View Course

Exercise instructions

  • Create an inputs message dictionary with the user's query as content for HumanMessage.
  • Stream msg and metadata from the chatbot app by iterating over the results using the .stream() method incorporating inputs and config.
  • Check if each msg has content and is not a HumanMessage, then print its content with flush set to True 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?")
Edit and Run Code