1. Learn
  2. /
  3. Courses
  4. /
  5. AI Agents with Hugging Face smolagents

Connected

Exercise

Stateful by Design: Build a RAG Search Tool

In the previous lesson, you saw how a vector-based knowledge base of appliance manuals can be built and searched using embeddings.

Now, you'll build a custom tool that wraps this search logic, so an agent can use it to answer appliance-related questions.

The tool you're writing will subclass the Tool base class and expose one input: a question about appliance operation

You already have access to:

  • A variable called vector_store, which contains your pre-built FAISS index
  • Document chunks with appliance manual content, embedded and ready for search

Your job is to implement the structure and logic of the tool that will make this knowledge base accessible to an agent.

Instructions

100 XP
  • Accept a vector_store parameter in the __init__() method.
  • Add query as the parameter to the forward() method.
  • Use self.k to set how many relevant documents should be returned from the similarity search.