Agentic RAG का परिचय

Hugging Face smolagents के साथ AI Agents

Adel Nehme

VP of AI Curriculum, DataCamp

Agentic RAG: Iterative Retrieval + Reasoning

Hugging Face smolagents के साथ AI Agents

smolagents में Stateless बनाम Stateful Tools

Function Tools (@tool decorator)

  • Stateless: कॉल्स के बीच कोई मेमोरी नहीं
  • कॉल्स के बीच आपका vector store याद नहीं रख सकते

Class-Based Tools (Tool subclass)

  • Stateful: कॉल्स के पार रेफरेंस बने रहते हैं
  • जटिल ऑब्जेक्ट स्टोर कर सकते हैं
Hugging Face smolagents के साथ AI Agents

Class-Based Tool की संरचना

from smolagents import Tool

class ToolName(Tool):
    name = "tool_name"

description = "Clear description for the agent"
inputs = { "parameter_name": {"type": "parameter_type", "description": "Parameter purpose"} } output_type = "string"
def __init__(self, custom_parameters): super().__init__() self.custom_attribute = custom_parameters
def forward(self, parameter_name): # Agent calls this method return "processed output"
Hugging Face smolagents के साथ AI Agents

Recipe Search Tool बनाएँ

class RecipeSearchTool(Tool):
    name = "recipe_search" 
    description = "Search cooking documentation for recipes, techniques, and meal planning information"
    inputs = {
        "query": {"type": "string", "description": "Natural language cooking query"}
    }
    output_type = "string"

def __init__(self, vectorstore, k=6): super().__init__() self.vectorstore = vectorstore self.k = k
def forward(self, query): docs = self.vectorstore.similarity_search(query, k=self.k) return "\n\n".join(doc.page_content for doc in docs) or "Nothing found."
Hugging Face smolagents के साथ AI Agents

Cooking Assistant Agent: सब कुछ एक साथ

# Initialize the retrieval tool
recipe_search = RecipeSearchTool(vector_store)

agent = CodeAgent(
    tools=[recipe_search],
    model=model,
    instructions="Search thoroughly to provide complete recipe answers. 
      If initial results seem incomplete, try different search terms.",
    verbosity_level=1,
    max_steps=8
)
Hugging Face smolagents के साथ AI Agents

Agent Run उदाहरण

Query: How do I cook salmon with herbs using professional techniques?

[Step 1] "salmon herbs cooking techniques" सर्च करें...

[Step 2] "professional salmon preparation" सर्च करें...

[Final Answer]

"फिलेट्स को सूखा पोंछें, जड़ी-बूटियाँ लगाएँ, और:

  • पैन में स्किन-साइड नीचे सेअर करें, बटर, लहसुन, थाइम से बेस्ट करें
  • या 200°C पर लेमन और हर्ब बटर के साथ 10–12 मिनट बेक करें"
Hugging Face smolagents के साथ AI Agents

अभ्यास करते हैं!

Hugging Face smolagents के साथ AI Agents

Preparing Video For Download...