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

Connected

Exercise

Creating a ReAct agent

Now that you've learned the basic components of LangChain, you'll jump right in and create a ReAct agent that can count how many 'r's there are in any word with the tool count_r_in_word.

The following have been loaded for you: tool, ChatOpenAI, create_react_agent, math, and model.

Instructions

100 XP
  • Set up the agent app using create_react_agent() by passing in the model and the count_r_in_word to the list of tools.
  • Define a query variable that accepts the user's question as a string.
  • Invoke the app with .invoke() and pass a dictionary with a "messages" key, labeling the query as "human".
  • Access the last message in the response and print its .content attribute to get the agent's answer.