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

Connected

Exercise

Build a Wikipedia tool

The school administration is quite happy with your work! They would like to make the chatbot even more powerful by incorporating external resources. You suggest equipping the chatbot with access to Wikipedia. The administration agrees to extend your commission, so you decide to build a tool for the chatbot using the Wikipedia API.

The following modules have been imported for you to get started: WikipediaQueryRun, WikipediaAPIWrapper

Instructions

100 XP
  • Create an api_wrapper that initializes WikipediaAPIWrapper() with top_k_results=1 to fetch only the top Wikipedia result.
  • Create a WikipediaQueryRun() tool called wikipedia_tool, passing in the api_wrapper as its input before saving it to a list called tools.
  • Bind the tools list to the llm by passing it to the .bind_tools() method.
  • To direct the chatbot to respond with the tool, pass the content of "messages" in state to the .invoke() method and apply it to llm_with_tools.