Einführung in Hugging Face smolagents

AI-Agents mit Hugging Face smolagents

Adel Nehme

VP of AI Curriculum, DataCamp

AI-Agents mit Hugging Face smolagents

AI-Agents mit Hugging Face smolagents

AI-Agents mit Hugging Face smolagents

AI-Agents mit Hugging Face smolagents

AI-Agents mit Hugging Face smolagents

Definition eines KI-Agenten

AI-Agents mit Hugging Face smolagents

Von Chatbots zu Agenten

Chatbots:

  • Antworten in natürlicher Sprache
  • Passiv und reaktiv

Agenten:

  • Können Aktionen ausführen (Websuche, Dateien lesen, Daten analysieren, etc.)
  • Handeln aktiv auf ein Ziel hin

Agenten folgen einem Zyklus:

AI-Agents mit Hugging Face smolagents

Beispiel: Wettbewerber-Preisforschung

Alles aus einem einzigen Prompt!

AI-Agents mit Hugging Face smolagents

Was sind smolagents?

  • Leichtgewichtiges Python-Framework
  • Entwickelt von Hugging Face

Unterstützt zwei Agententypen:

  • ToolCallingAgent: Nutzt strukturierte Funktionsaufrufe
  • CodeAgent: Schreibt und führt Python-Code aus
AI-Agents mit Hugging Face smolagents

Wie Funktionsaufrufe funktionieren

Action 1: {"tool": "search_company", "company": "Competitor A"}
Action 2: {"tool": "get_pricing", "company": "Competitor A", "plan": "Basic"}
Action 3: {"tool": "get_pricing", "company": "Competitor A", "plan": "Pro"}
Action 4: {"tool": "search_company", "company": "Competitor B"}
Action 5: {"tool": "get_pricing", "company": "Competitor B", "plan": "Basic"}
AI-Agents mit Hugging Face smolagents

Wie Code-Agenten arbeiten

competitors = ["Competitor A", "Competitor B", "Competitor C"]
pricing_data = {}

for company in competitors:
    company_info = search_company(company)
    plans = extract_pricing_plans(company_info)
    pricing_data[company] = plans

most_affordable_option = min(pricing_data, 
                      key=lambda x: pricing_data[x]['basic_plan'])
AI-Agents mit Hugging Face smolagents

Der Code-Agenten-Ablauf

Forschung zeigt ~20% höhere Erfolgsrate als Funktionsaufrufmethoden.

1 https://huggingface.co/papers/2402.01030
AI-Agents mit Hugging Face smolagents

Lass uns üben!

AI-Agents mit Hugging Face smolagents

Preparing Video For Download...