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

Connected

Exercise

Ask questions about conversation history

With a basic ReAct agent in LangChain, you can ask follow-up questions by keeping the agent's conversation history. Since the LLM has access to all previous messages, you can now ask new questions, and the agent can use the full message context to respond.

You'll now ask a follow-up question about the sides of a different triangle.

To be able to use the HumanMessage and AIMessage capabilities, the following modules have already been imported for you: HumanMessage, AIMessage.

Instructions

100 XP
  • Assign the given natural language question to new_query.
  • Invoke the app object, passing in all of the messages, including the message_history and the new_query.
  • Use a list comprehension to extract messages from response["messages"] labeled HumanMessage or AIMessage.
  • Pass the new query as input and print the extracted messages by passing the message classes to "agent_output".