Hugging Face smolagents로 AI 에이전트 만들기
Adel Nehme
VP of AI Curriculum, DataCamp


from smolagents import tool
import pandas as pd
@tool
def check_inventory(product_name: str) -> int:
"""
재고 CSV에서 제품의 가용 수량을 확인합니다.
Args:
product_name (str): 조회할 제품명.
Returns:
int: 재고 수량. 없으면 0을 반환.
"""
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

티셔츠 재고가 있나요?

from smolagents import CodeAgent
agent = CodeAgent(
tools=[check_inventory], # Add custom tool
model=InferenceClientModel(),
additional_authorized_imports=["pandas"] # Allow external package
)
agent.run("Do we have any large t-shirts in stock?")
Yes, we have 8 large t-shirts in stock.

Hugging Face smolagents로 AI 에이전트 만들기