도구로 에이전트 만들기

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

Adel Nehme

VP of AI Curriculum, DataCamp

코드 에이전트 생성(도구 없음)

from smolagents import CodeAgent, InferenceClientModel

agent = CodeAgent(
    tools=[],
    model=InferenceClientModel()
)

agent.run("Calculate the average of the list [23, 45, 67, 89]")
Executing parsed code:
  numbers = [23, 45, 67, 89]                                                                               
  average = sum(numbers) / len(numbers)                                                                            
  final_answer(average)                                                                                             
Final answer: 56.0
[Step 1: Duration 4.14 seconds| Input tokens: 1,900 | Output tokens: 109]
56.0
Hugging Face smolagents로 AI 에이전트 만들기

왜 코드 에이전트에 도구를 쓰나요?

정의한 에이전트는 이미 다음으로 많은 작업을 해결합니다:

  • LLM 모델
  • Python 코드

하지만 외부 정보가 필요할 수 있습니다:

  • 예: 실시간 웹 데이터

바로 여기에 도구가 필요합니다!

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

웹 검색 도구 추가

from smolagents import CodeAgent, InferenceClientModel, WebSearchTool

agent = CodeAgent(
    model=InferenceClientModel(),
    tools=[WebSearchTool()]
)
Hugging Face smolagents로 AI 에이전트 만들기

웹 검색 도구가 있는 코드 에이전트 출력

agent.run("What's the tallest building in the world right now?")
Executing parsed code:
  tallest_building_info = web_search("tallest building in the world 2023")                                
  print(tallest_building_info)                                                                                

# Search results omitted for brevity...

Executing parsed code: 
  final_answer("Burj Khalifa, Dubai, 828 meters")                                                              
Final answer: Burj Khalifa, Dubai, 828 meters
[Step 2: Duration 2.97 seconds| Input tokens: 5,078 | Output tokens: 153]
Burj Khalifa, Dubai, 828 meters
Hugging Face smolagents로 AI 에이전트 만들기

카테고리별 기본 제공 도구

범주 도구
정보 검색 ApiWebSearchTool, DuckDuckGoSearchTool, GoogleSearchTool, WebSearchTool, WikipediaSearchTool
웹 상호작용 VisitWebpageTool
코드 실행 PythonInterpreterTool
사용자 상호작용 UserInputTool
음성 처리 SpeechToTextTool
워크플로 제어 FinalAnswerTool
1 https://huggingface.co/docs/smolagents/main/en/reference/default_tools
Hugging Face smolagents로 AI 에이전트 만들기

Hugging Face Hub의 도구

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

Hugging Face 커뮤니티 도구 사용

from smolagents import load_tool

# Load remote tool from Hugging Face
model_downloads_tool = load_tool(
    repo_id="example-repo/hf-model-downloads",
    trust_remote_code=True
)

# Create agent with remote + built-in tools
agent = CodeAgent(
    tools=[model_downloads_tool, WebSearchTool()],
    model=InferenceClientModel()
)

agent.run("Find the most downloaded image classification model on Hugging Face")
google/vit-base-patch16-224-in21k
Hugging Face smolagents로 AI 에이전트 만들기

연습해 봅시다!

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

Preparing Video For Download...