πŸ€— 02. HF Agents Course 본편 2 - λ©€ν‹° 툴 μ—μ΄μ „νŠΈμ™€ μ‹€ν–‰ 둜그 검증

1νŽΈμ—μ„œ 단일 검색 νˆ΄μ„ λΆ™μ˜€λ‹€λ©΄, μ΄λ²ˆμ—λŠ” 검색 + 계산 + 검증 좜λ ₯κΉŒμ§€ ν•œ λ²ˆμ— μž¬ν˜„ν•œλ‹€. 핡심은 β€œκ²°κ³Ό ν…μŠ€νŠΈβ€κ°€ μ•„λ‹ˆλΌ **μ‹€ν–‰ 흔적(tool call + 둜그)**κΉŒμ§€ ν™•μΈν•˜λŠ” μŠ΅κ΄€μ΄λ‹€.

였늘 μ‹€μŠ΅ λͺ©ν‘œ

  • smolagents에 툴 2개(검색/계산) μ—°κ²°
  • ν•˜λ‚˜μ˜ ν”„λ‘¬ν”„νŠΈμ—μ„œ 순차 도ꡬ μ‚¬μš© μœ λ„
  • μ‹€ν–‰ λ‘œκ·Έμ™€ μ΅œμ’… κ²°κ³Όλ₯Ό 파일둜 남겨 성곡 νŒμ •

전체 흐름

flowchart TD
  A[ν™˜κ²½ ν™œμ„±ν™”] --> B[λ©€ν‹° 툴 μ—μ΄μ „νŠΈ μ½”λ“œ μž‘μ„±]
  B --> C[ν”„λ‘¬ν”„νŠΈ μ‹€ν–‰]
  C --> D[tool call 둜그 확인]
  D --> E[κ²°κ³Ό 파일 μ €μž₯]
  E --> F{성곡 νŒμ •}
  F -->|Yes| G[μž¬ν˜„ μ™„λ£Œ]
  F -->|No| H[ν”„λ‘¬ν”„νŠΈ/토큰/νŒ¨ν‚€μ§€ 점검]

사전 μ€€λΉ„

도ꡬ

  • Python 3.10+
  • 터미널
  • Hugging Face Access Token

μž…λ ₯κ°’

  • HF_TOKEN
  • ν…ŒμŠ€νŠΈ 질문:
    • "Find 2 recent AI agent headlines, then estimate monthly visits if daily visits are 1200 and weekends are 30% lower. Answer in Korean with sources."

μ‹€μŠ΅ 단계

1) μž‘μ—… 폴더 이동 + κ°€μƒν™˜κ²½ ν™œμ„±ν™”

cd hf-agents-ep01
source .venv/bin/activate

2) μ‹€ν–‰ 파일 μž‘μ„± (run_ep02.py)

from smolagents import CodeAgent, DuckDuckGoSearchTool, PythonInterpreterTool, HfApiModel
 
model = HfApiModel(model_id="Qwen/Qwen2.5-Coder-32B-Instruct")
agent = CodeAgent(
    tools=[DuckDuckGoSearchTool(), PythonInterpreterTool()],
    model=model,
    add_base_tools=True,
)
 
prompt = (
    "Find 2 recent AI agent headlines, then estimate monthly visits "
    "if daily visits are 1200 and weekends are 30% lower. "
    "Answer in Korean with source links and show the calculation logic."
)
 
result = agent.run(prompt)
print(result)
 
with open("ep02_result.txt", "w", encoding="utf-8") as f:
    f.write(str(result))

3) μ‹€ν–‰

python run_ep02.py | tee ep02_run.log

성곡 νŒμ • (ν•„μˆ˜ 4개)

  1. ep02_run.log에 검색 κ΄€λ ¨ tool call 흔적이 μžˆλ‹€.
  2. 계산(평일/주말 κ°€μ€‘μΉ˜) μ„€λͺ…이 ν•œκ΅­μ–΄λ‘œ ν¬ν•¨λœλ‹€.
  3. 결과에 좜처 링크가 2개 이상 ν¬ν•¨λœλ‹€.
  4. ep02_result.txt 파일이 μƒμ„±λ˜κ³  λΉ„μ–΄μžˆμ§€ μ•Šλ‹€.

초보자 체크포인트

  • ImportErrorκ°€ λ‚˜λ©΄ pip install -U smolagents duckduckgo-search litellm μž¬μ‹€ν–‰
  • 401/403이면 echo $HF_TOKEN으둜 토큰 μ„€μ • 확인
  • κ²°κ³Ό 포맷이 λΆˆμ•ˆμ •ν•˜λ©΄ ν”„λ‘¬ν”„νŠΈ 끝에 "번호 λͺ©λ‘ 1~2둜 좜λ ₯" 같은 ν˜•μ‹ μ œμ•½μ„ μΆ”κ°€

싀무 적용 포인트

  • 이 νŒ¨ν„΄μ€ μ½˜ν…μΈ  λ¦¬μ„œμΉ˜ + 간단 수치 μΆ”μ • μžλ™ν™”μ— λ°”λ‘œ μ“Έ 수 μžˆλ‹€.
  • 특히 aiee.app μš΄μ˜μ—μ„œλŠ” β€œκ·Όκ±° 링크 + 계산 근거”λ₯Ό ν•¨κ»˜ 남기면 νŽΈμ§‘ κ²€μˆ˜ μ‹œκ°„μ΄ 쀄어든닀.
  • λ‹€μŒ νŽΈμ—μ„œλŠ” μ—μ΄μ „νŠΈ 좜λ ₯ μŠ€ν‚€λ§ˆ(JSON) κ°•μ œλ‘œ ν›„μ²˜λ¦¬ νŒŒμ΄ν”„λΌμΈμ— μ—°κ²°ν•œλ‹€.

μƒμ„±ν˜• AI ν™œμš© κ³ μ§€

이 λ¬Έμ„œλŠ” μƒμ„±ν˜• AIλ₯Ό ν™œμš©ν•΄ μ΄ˆμ•ˆμ„ μž‘μ„±ν–ˆμœΌλ©°, μ‚¬λžŒμ΄ μ‹€μŠ΅ μž¬ν˜„μ„±(λͺ…λ Ή/μž…λ ₯/성곡 νŒμ •)κ³Ό 싀무 μ μš©μ„±μ„ κ²€μˆ˜ν•΄ ν™•μ •ν–ˆλ‹€.