Agenti AI con Hugging Face smolagents
Adel Nehme
VP of AI Curriculum, DataCamp


from smolagents import tool
import pandas as pd
@tool
def check_inventory(product_name: str) -> int:
"""
Controlla la quantità disponibile di un prodotto nel CSV dell'inventario.
Args:
product_name (str): Nome del prodotto da cercare.
Returns:
int: Quantità in magazzino. Ritorna 0 se il prodotto non è trovato.
"""
df = pd.read_csv("store_inventory.csv")
match = df[df["product_name"] == product_name]
stock_quantity = int(match.iloc[0]["quantity"]) if not match.empty else 0
return stock_quantity

Abbiamo magliette in magazzino?

from smolagents import CodeAgent
agent = CodeAgent(
tools=[check_inventory], # Aggiungi strumento personalizzato
model=InferenceClientModel(),
additional_authorized_imports=["pandas"] # Consenti pacchetto esterno
)
agent.run("Abbiamo magliette grandi in magazzino?")
Sì, abbiamo 8 magliette grandi in magazzino.

Agenti AI con Hugging Face smolagents