SmolAgents, HuggingFace๐Ÿค—๊ฐ€ ๊ณต๊ฐœํ•œ LLM ์ค‘์‹ฌ์˜ Agent ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

SmolAgents, HuggingFace:hugs:๊ฐ€ ๊ณต๊ฐœํ•œ LLM ์ค‘์‹ฌ์˜ Agent ๊ธฐ๋Šฅ ๊ตฌํ˜„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ

SmolAgents ์†Œ๊ฐœ

Hugging Face๋Š” AI ์–ธ์–ด ๋ชจ๋ธ(LLM)์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ๊ฐ„์†Œํ™”ํ•˜๊ณ  ์—์ด์ „ํŠธ๋ฅผ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ๋Ÿ‰ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ธ Smolagents๋ฅผ ๊ณต๊ฐœํ–ˆ์Šต๋‹ˆ๋‹ค. ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” LLM์ด ์™ธ๋ถ€ ๋„๊ตฌ์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜๋ฉฐ ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋Šฅ๋ ฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. Smolagents๋Š” ๋‹จ์ˆœ์„ฑ๊ณผ ํšจ์œจ์„ฑ์— ์ค‘์ ์„ ๋‘๊ณ  ์„ค๊ณ„๋˜์–ด Python ์ฝ”๋“œ ๊ธฐ๋ฐ˜์˜ ์•ก์…˜์„ ์ž‘์„ฑํ•˜๋Š” ์—์ด์ „ํŠธ๋ฅผ ์‰ฝ๊ฒŒ ๋งŒ๋“ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel

agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())

agent.run("ํ‘œ๋ฒ”์ด ์ „์†๋ ฅ์œผ๋กœ ํ๋ฐ์ž๋ฅด(Pont des Arts) ๊ฑฐ๋ฆฌ๋ฅผ ๋‹ฌ๋ฆฌ๋Š”๋ฐ ๋ช‡ ์ดˆ๋‚˜ ๊ฑธ๋ฆด๊นŒ์š”?")

Agent๋ž€ ๋ฌด์—‡์ธ๊ฐ€์š”? :thinking:

AI Agent๋Š” LLM์˜ ์ถœ๋ ฅ์œผ๋กœ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์ œ์–ดํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์ž…๋‹ˆ๋‹ค.

AI Agents are programs where LLM outputs control the workflow .

์ด๋Ÿฌํ•œ AI Agent์˜ ์ •์˜์—์„œ '์—์ด์ „ํŠธ'๋Š” (0 ๋˜๋Š” 1๊ณผ ๊ฐ™์€) ๋ถˆ์—ฐ์†์ ์ธ ์ •์˜๊ฐ€ ์•„๋‹ˆ๋ผ, ์›Œํฌํ”Œ๋กœ์šฐ์—์„œ LLM์— ๋” ๋งŽ๊ฑฐ๋‚˜ ์ ์€ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•จ์— ๋”ฐ๋ผ ์—ฐ์†์ ์ธ ์ŠคํŽ™ํŠธ๋Ÿผ์œผ๋กœ ์ง„ํ™”ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์•„๋ž˜ ํ‘œ์™€ ๊ฐ™์ด ์‹œ์Šคํ…œ์— ๋”ฐ๋ผ ์—์ด์ „์‹œ๊ฐ€ ์–ด๋–ป๊ฒŒ ๋‹ฌ๋ผ์ง€๋Š”์ง€๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

์—์ด์ „์‹œ ์ˆ˜์ค€(Agency Level) ์„ค๋ช… ํ˜ธ์ถœ ๋ฐฉ์‹ ์˜ˆ์‹œ ํŒจํ„ด(Example Pattern)
โ˜†โ˜†โ˜† LLM ์ถœ๋ ฅ์€ ํ”„๋กœ๊ทธ๋žจ ํ๋ฆ„์— ์˜ํ–ฅ์„ ๋ฏธ์น˜์ง€ ์•Š์Œ ๋‹จ์ˆœ ํ”„๋กœ์„ธ์„œ(Simple Processor) process_llm_output(llm_response)
โ˜…โ˜†โ˜† LLM ์ถœ๋ ฅ์œผ๋กœ ๊ธฐ๋ณธ ์ œ์–ด ํ๋ฆ„์„ ๊ฒฐ์ • ๋ผ์šฐํ„ฐ(Router) if llm_decision(): path_a() else: path_b()
โ˜…โ˜…โ˜† LLM ์ถœ๋ ฅ์œผ๋กœ ํ•จ์ˆ˜ ์‹คํ–‰์„ ๊ฒฐ์ • ๋„๊ตฌ ํ˜ธ์ถœ(Tool Call) run_function(llm_chosen_tool, llm_chosen_args)
โ˜…โ˜…โ˜… LLM ์ถœ๋ ฅ์œผ๋กœ ๋ฐ˜๋ณต๊ณผ ํ”„๋กœ๊ทธ๋žจ ์—ฐ์†์„ฑ ์ œ์–ด ๋‹ค๋‹จ๊ณ„ ์—์ด์ „ํŠธ(Multi-step Agent) while llm_should_continue(): execute_next_step()
โ˜…โ˜…โ˜… ํ•˜๋‚˜์˜ ์—์ด์ „ํŠธ ์›Œํฌํ”Œ๋กœ๊ฐ€ ๋‹ค๋ฅธ ์—์ด์ „ํŠธ ์›Œํฌํ”Œ๋กœ๋ฅผ ์‹œ์ž‘ํ•  ์ˆ˜ ์žˆ์Œ ๋ฉ€ํ‹ฐ ์—์ด์ „ํŠธ(Multi-Agent) if llm_trigger(): execute_agent()

๋‹ค๋‹จ๊ณ„ ์—์ด์ „ํŠธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ ๊ตฌ์กฐ๋ฅผ ๊ฐ–์Šต๋‹ˆ๋‹ค:

memory = [user_defined_task]                 # ์‚ฌ์šฉ์ž๊ฐ€ ์‚ฌ์ „์— ์ •์˜ํ•œ ์ž‘์—…
while llm_should_continue(memory):       # ๋‹ค๋‹จ๊ณ„(Multi-Step) ๋ฐ˜๋ณต ๋ถ€๋ถ„
    action = llm_get_next_action(memory) # ๋„๊ตฌ ํ˜ธ์ถœ ๋ถ€๋ถ„
    observations = execute_action(action)
    memory += [action, observations]

์ด๋Ÿฌํ•œ ์‹œ์Šคํ…œ์€ ์ฃผ์–ด์ง„ ์ž‘์—…์„ ๋งŒ์กฑ์Šค๋Ÿฝ๊ฒŒ ํ•ด๊ฒฐํ–ˆ๋‹ค๊ณ  ํŒ๋‹จํ•  ๋•Œ๊นŒ์ง€ ๊ฐ ๋‹จ๊ณ„๋งˆ๋‹ค ์ƒˆ๋กœ์šด ์ž‘์—…์„ ์‹คํ–‰ํ•˜๋Š” ๋ฃจํ”„๋ฅผ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ์€ ๋‹ค๋‹จ๊ณ„ ์—์ด์ „ํŠธ๊ฐ€ ๊ฐ„๋‹จํ•œ ์ˆ˜ํ•™ ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค:
SmolAgents: ๋‹ค๋‹จ๊ณ„ ์—์ด์ „ํŠธ๊ฐ€ ๊ฐ„๋‹จํ•œ ์ˆ˜ํ•™ ๋ฌธ์ œ๋ฅผ ํ‘ธ๋Š” ์˜ˆ์‹œ

Agent๋Š” :white_check_mark:์–ธ์ œ ์‚ฌ์šฉํ•˜๊ณ  :no_entry:์–ธ์ œ ์‚ฌ์šฉํ•˜์ง€ ์•Š์•„์•ผ ํ• ๊นŒ์š”?

:white_check_mark: ์—์ด์ „ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ƒํ™ฉ

์—์ด์ „ํŠธ๋Š” AI ์–ธ์–ด ๋ชจ๋ธ(LLM)์ด ์•ฑ์˜ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ๊ฒฐ์ •ํ•ด์•ผ ํ•˜๋Š” ์ƒํ™ฉ์—์„œ ์œ ์šฉํ•ฉ๋‹ˆ๋‹ค. ํŠนํžˆ, ์‚ฌ์ „์— ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ๋ช…ํ™•ํžˆ ์ •์˜ํ•˜๊ธฐ ์–ด๋ ค์šด ๋ณต์žกํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ๋•Œ ํ•„์ˆ˜์ ์ž…๋‹ˆ๋‹ค.

์˜ˆ์‹œ: ๋ณต์žกํ•œ ์‚ฌ์šฉ์ž ์š”์ฒญ

  • ์‚ฌ์šฉ์ž๊ฐ€ ๋ณต์žกํ•œ ์กฐ๊ฑด์„ ์ œ์‹œํ•˜๋ฉฐ ํŠน์ •ํ•œ ์š”๊ตฌ๋ฅผ ํ•  ๊ฒฝ์šฐ:
    • ์š”์ฒญ: "์›”์š”์ผ์— ์˜ฌ ์ˆ˜ ์žˆ์ง€๋งŒ, ์—ฌ๊ถŒ์„ ์žŠ์–ด ์ˆ˜์š”์ผ๋กœ ์ง€์—ฐ๋  ๊ฐ€๋Šฅ์„ฑ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ™”์š”์ผ ์•„์นจ์— ๋‚˜์™€ ์ง์„ ํ•จ๊ป˜ ์„œํ•‘ ์žฅ์†Œ๋กœ ์ด๋™์‹œํ‚ค๊ณ  ์‹ถ์Šต๋‹ˆ๋‹ค. ์ทจ์†Œ ๋ณดํ—˜์„ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ์„๊นŒ์š”?"
    • ํŠน์ง•: ์ด๋Ÿฌํ•œ ์š”์ฒญ์€ ์—ฌ๋Ÿฌ ๋ณ€์ˆ˜(๋‚ ์”จ, ๊ฑฐ๋ฆฌ, ์ง์› ๊ฐ€์šฉ์„ฑ ๋“ฑ)์— ์˜์กดํ•˜๋ฉฐ, ๋ฏธ๋ฆฌ ์ •์˜๋œ ๊ธฐ์ค€๋งŒ์œผ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.

์ด๋Ÿฐ ๊ฒฝ์šฐ, ์—์ด์ „ํŠธ ๊ธฐ๋ฐ˜ ์„ค๊ณ„๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ์—์ด์ „ํŠธ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋„๊ตฌ์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜์—ฌ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•ฉ๋‹ˆ๋‹ค:

  • ๋‚ ์”จ API: ๋‚ ์”จ ์ •๋ณด๋ฅผ ํ™•์ธ
  • Google Maps API: ์ด๋™ ๊ฑฐ๋ฆฌ ๊ณ„์‚ฐ
  • ์ง์› ๋Œ€์‹œ๋ณด๋“œ: ์ง์› ๊ฐ€์šฉ์„ฑ ์กฐํšŒ
  • RAG ์‹œ์Šคํ…œ: ์ง€์‹ ๊ธฐ๋ฐ˜ ๊ฒ€์ƒ‰

์—์ด์ „ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ์ƒํ™ฉ

๊ฐ„๋‹จํ•˜๊ณ  ๊ณ ์ •๋œ ์›Œํฌํ”Œ๋กœ์šฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” ๊ฒฝ์šฐ, ์—์ด์ „ํŠธ๋Š” ๋ถˆํ•„์š”ํ•˜๋ฉฐ ์˜คํžˆ๋ ค ๋น„ํšจ์œจ์ ์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์˜ˆ์‹œ: ์„œํ•‘ ์—ฌํ–‰ ์›น์‚ฌ์ดํŠธ์˜ ๊ธฐ๋ณธ ์š”์ฒญ

  • ์š”์ฒญ์ด ๋ช…ํ™•ํ•˜๊ฒŒ ๋‘ ๊ฐ€์ง€ ๋ฒ”์ฃผ๋กœ ๋‚˜๋‰˜๋Š” ๊ฒฝ์šฐ:
    1. ์—ฌํ–‰ ์ •๋ณด ์š”์ฒญ: ์‚ฌ์šฉ์ž๊ฐ€ ๊ฒ€์ƒ‰์ฐฝ์—์„œ ์ •๋ณด๋ฅผ ํƒ์ƒ‰.
    2. ์˜์—…ํŒ€ ์ƒ๋‹ด ์š”์ฒญ: ์‚ฌ์šฉ์ž๊ฐ€ ์—ฐ๋ฝ ์–‘์‹์„ ์ž‘์„ฑ.

์ด์™€ ๊ฐ™์€ ๊ฒฐ์ •๋ก ์  ์›Œํฌํ”Œ๋กœ์šฐ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์€ ํŠน์ง•์„ ๊ฐ€์ง‘๋‹ˆ๋‹ค:

  • ์˜ˆ์ธก ๊ฐ€๋Šฅ์„ฑ: ์š”์ฒญ์˜ ๋ฒ”์ฃผ๊ฐ€ ์‚ฌ์ „์— ์ •์˜ ๊ฐ€๋Šฅ.
  • ์‹ ๋ขฐ์„ฑ: ์—์ด์ „ํŠธ๋ฅผ ๋„์ž…ํ•˜์ง€ ์•Š์•„๋„ 100% ์‹ ๋ขฐ ๊ฐ€๋Šฅํ•œ ๊ฒฐ๊ณผ ์ œ๊ณต.
  • ๋‹จ์ˆœ์„ฑ: LLM์˜ ์˜ˆ์ธก ์˜ค๋ฅ˜๋กœ ์ธํ•œ ์œ„ํ—˜ ์ œ๊ฑฐ.

๊ฒฐ๋ก ์ ์œผ๋กœ, ๋‹จ์ˆœํ•˜๊ณ  ๋ช…ํ™•ํ•œ ์›Œํฌํ”Œ๋กœ์šฐ์—์„œ๋Š” ์—์ด์ „ํŠธ๋ฅผ ๋ฐฐ์ œํ•˜๊ณ  ์ „ํ†ต์ ์ธ ์ฝ”๋”ฉ ๋ฐฉ์‹์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š” ๊ฒƒ์ด ๋” ํšจ์œจ์ ์ž…๋‹ˆ๋‹ค.

์ฝ”๋“œ ์—์ด์ „ํŠธ(Code Agents)

๋‹ค๋‹จ๊ณ„ ์—์ด์ „ํŠธ(Multi-Step Agents)์—์„œ ๊ฐ ๋‹จ๊ณ„๋งˆ๋‹ค LLM์€ ์™ธ๋ถ€ ๋„๊ตฌ์— ๋Œ€ํ•œ ํ˜ธ์ถœ์˜ ํ˜•ํƒœ๋กœ ์•ก์…˜(Action)์„ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. OpenAI๋‚˜ Anthropic ๋“ฑ์—์„œ๋Š” ์ด๋Ÿฌํ•œ ์•ก์…˜์„ '์‚ฌ์šฉํ•  ๋„๊ตฌ(ํ•จ์ˆ˜) ์ด๋ฆ„๊ณผ ์ธ์ž๋ฅผ JSON ํ˜•ํƒœ'๋กœ ์ž‘์„ฑํ•˜๊ณ , ์ด๋ฅผ ํŒŒ์‹ฑํ•˜์—ฌ ์–ด๋– ํ•œ ๋„๊ตฌ๋ฅผ ์–ด๋– ํ•œ ์ธ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์‹คํ–‰ํ• ์ง€ ํŒŒ์•…ํ•ฉ๋‹ˆ๋‹ค.

๊ทธ๋Ÿฌ๋‚˜ ๋‹ค์ˆ˜์˜ ์—ฐ๊ตฌ ๊ฒฐ๊ณผ๋“ค([1][2][3])์— ๋”ฐ๋ฅด๋ฉด, JSON ๋Œ€์‹  ์ฝ”๋“œ๋กœ ๋„๊ตฌ ํ˜ธ์ถœ์„ ์ž‘์„ฑํ•˜๋Š” ๋ฐฉ์‹์ด ํ›จ์”ฌ ๋” ํšจ์œจ์ ์ด๊ณ  ์œ ์—ฐํ•˜๋‹ค๋Š” ์ ์ด ์ž…์ฆ๋˜์—ˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ์šฐ๋ฆฌ๊ฐ€ ์ปดํ“จํ„ฐ๊ฐ€ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฉ์‹์œผ๋กœ JSON ์กฐ๊ฐ(Snippet) ๋Œ€์‹  ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ๋‹ค์Œ์€ "Executable Code Actions Elicit Better LLM Agents" ์—ฐ๊ตฌ์—์„œ ์ฝ”๋“œ๋กœ ์•ก์…˜์„ ์ž‘์„ฑํ•  ๋•Œ์˜ ๋ช‡ ๊ฐ€์ง€ ์ด์ ์„ ์ •๋ฆฌํ•œ ๊ธ€์ž…๋‹ˆ๋‹ค:

ํŠนํžˆ, ๊ตฌ์„ฑ ๊ฐ€๋Šฅ์„ฑ(Composability), ๊ฐ์ฒด ๊ด€๋ฆฌ(Object Management), ์ผ๋ฐ˜์„ฑ(Generality) ๋ฐ LLM ํ•™์Šต ๋ฐ์ดํ„ฐ์˜ ํ‘œํ˜„(Representation in LLM training data)์—์„œ JSON๋ณด๋‹ค ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋กœ ์ž‘์„ฑํ•œ ์ฝ”๋“œ๋กœ ์•ก์…˜์„ ์ž‘์„ฑํ•˜๋Š” ๊ฒƒ์ด ๋” ๋‚ซ์Šต๋‹ˆ๋‹ค.

SmolAgnets ์†Œ๊ฐœ: ๋” ๊ฐ„๋‹จํ•˜๊ณ  ๊ฐ•๋ ฅํ•œ ์—์ด์ „ํŠธ ๊ตฌ์ถ•์„ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ :partying_face:

SmolAgents๋Š” transformers.agents์˜ ํ›„์† ๋ฒ„์ „์œผ๋กœ, ํ–ฅํ›„ transformers.agents๊ฐ€ ๋” ์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š๊ฒŒ ๋˜๋ฉด ์ด๋ฅผ ๋Œ€์ฒดํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.

SmolAgents๋ฅผ ๋งŒ๋“ค ๋•Œ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ชฉํ‘œ๋“ค์„ ๊ณ ๋ คํ•˜์˜€์Šต๋‹ˆ๋‹ค:

  • :sparkles: ๋‹จ์ˆœ์„ฑ(Simplicity)
    • ์—์ด์ „ํŠธ ๋กœ์ง์€ ์•ฝ 1000์ค„์˜ ์ฝ”๋“œ๋กœ ๊ตฌ์„ฑ๋ฉ๋‹ˆ๋‹ค.
    • ๋ถˆํ•„์š”ํ•œ ์ถ”์ƒํ™”๋ฅผ ์ œ๊ฑฐํ•˜๊ณ  ์›์‹œ ์ฝ”๋“œ ์œ„์— ์ตœ์†Œํ•œ์˜ ๊ตฌ์กฐ๋งŒ ์ถ”๊ฐ€ํ–ˆ์Šต๋‹ˆ๋‹ค.
  • :technologist: ์ฝ”๋“œ ์—์ด์ „ํŠธ ์ง€์›(First-class support for Code Agents)
    • ์—์ด์ „ํŠธ๊ฐ€ Python ์ฝ”๋“œ๋กœ ๋™์ž‘์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
    • ๋ณด์•ˆ์„ ์œ„ํ•ด E2B๋ฅผ ํ†ตํ•œ ์ƒŒ๋“œ๋ฐ•์Šค ํ™˜๊ฒฝ์„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
    • JSON ๊ธฐ๋ฐ˜ ํ…์ŠคํŠธ ์•ก์…˜์„ ์ž‘์„ฑํ•˜๋Š” ToolCallingAgent๋„ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
  • :hugs: ํ—ˆ๋ธŒ ํ†ตํ•ฉ(Hub integrations)
    • ๋„๊ตฌ๋ฅผ Hugging Face Hub์— ๊ณต์œ ํ•˜๊ฑฐ๋‚˜ Hub์—์„œ ๋กœ๋“œํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • :globe_with_meridians: ๋‹ค์–‘ํ•œ LLM ์ง€์›(Support for any LLM)
    • Hugging Face์˜ transformers ๋ชจ๋ธ๊ณผ API๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
    • OpenAI, Anthropic ๋“ฑ ๋‹ค์–‘ํ•œ ํด๋ผ์šฐ๋“œ LLM์„ LiteLLM์„ ํ†ตํ•ด ํ†ตํ•ฉ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

์—์ด์ „ํŠธ ๊ตฌ์ถ• ๋ฐฉ๋ฒ•

SmolAgents๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์—์ด์ „ํŠธ๋ฅผ ๊ตฌ์ถ•ํ•˜๋ ค๋ฉด ๋‹ค์Œ ๋‘ ๊ฐ€์ง€ ์š”์†Œ๊ฐ€ ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค:

  • Tools (๋„๊ตฌ)
    ์—์ด์ „ํŠธ๊ฐ€ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•œ ๋„๊ตฌ์˜ ๋ชฉ๋ก์ž…๋‹ˆ๋‹ค.
    ๋„๊ตฌ๋Š” Python ํ•จ์ˆ˜๋กœ ์ž‘์„ฑ๋˜๋ฉฐ, ํ•จ์ˆ˜์˜ ์ž…๋ ฅ๊ณผ ์ถœ๋ ฅ์— ํƒ€์ž… ํžŒํŠธ๋ฅผ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. @tool ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋„๊ตฌ๋กœ ๋“ฑ๋กํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • Model (๋ชจ๋ธ)
    ์—์ด์ „ํŠธ์˜ ์—”์ง„ ์—ญํ• ์„ ํ•˜๋Š” ์–ธ์–ด ๋ชจ๋ธ(LLM)์ž…๋‹ˆ๋‹ค.
    • Hugging Face API๋ฅผ ์‚ฌ์šฉํ•˜๋Š” HfApiModel
    • 100๊ฐœ ์ด์ƒ์˜ ํด๋ผ์šฐ๋“œ LLM์„ ์ง€์›ํ•˜๋Š” LiteLLMModel

๋‹ค์Œ์€ Google Maps API๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋‘ ์žฅ์†Œ ๊ฐ„ ์ด๋™ ์‹œ๊ฐ„์„ ๊ณ„์‚ฐํ•˜๋Š” ์‚ฌ์šฉ์ž ์ •์˜ ๋„๊ตฌ์™€ ์ด๋ฅผ ํ™œ์šฉํ•œ ์—ฌํ–‰ ๊ณ„ํš ์—์ด์ „ํŠธ๋ฅผ ๊ตฌ์„ฑํ•˜๋Š” ์˜ˆ์‹œ ์ฝ”๋“œ์ž…๋‹ˆ๋‹ค:

from typing import Optional
from smolagents import CodeAgent, HfApiModel, tool

@tool
def get_travel_duration(start_location: str, destination_location: str, departure_time: Optional[int] = None) -> str:
    """Gets the travel time in car between two places.
    
    Args:
        start_location: the place from which you start your ride
        destination_location: the place of arrival
        departure_time: the departure time, provide only a `datetime.datetime` if you want to specify this
    """
    import googlemaps # All imports are placed within the function, to allow for sharing to Hub.
    import os

    gmaps = googlemaps.Client(os.getenv("GMAPS_API_KEY"))

    if departure_time is None:
        from datetime import datetime
        departure_time = datetime(2025, 1, 6, 11, 0)

    directions_result = gmaps.directions(
        start_location,
        destination_location,
        mode="transit",
        departure_time=departure_time
    )
    return directions_result[0]["legs"][0]["duration"]["text"]

agent = CodeAgent(tools=[get_travel_duration], model=HfApiModel(), additional_authorized_imports=["datetime"])

agent.run("ํŒŒ๋ฆฌ ์‹œ๋‚ด๋ฅผ ๋‘˜๋Ÿฌ๋ณผ ์ˆ˜ ์žˆ๋Š” ์žฅ์†Œ์™€ ์‹œ๊ฐ„์„ ์•Œ๋ ค์ฃผ์‹œ๊ฒ ์–ด์š”? ์‹œ๋‚ด๋“  ์™ธ๊ณฝ์ด๋“  ์ƒ๊ด€์—†์ง€๋งŒ ํ•˜๋ฃจ ์ •๋„๋ฉด ์ถฉ๋ถ„ํ•ฉ๋‹ˆ๋‹ค. ์ €๋Š” ๋Œ€์ค‘๊ตํ†ต์œผ๋กœ๋งŒ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.")

์œ„์™€ ๊ฐ™์€ ์‚ฌ์šฉ์ž์˜ ์ž…๋ ฅ์— ๋”ฐ๋ผ ์—ฌ๋Ÿฌ ๋„๊ตฌ๋“ค์„ ํ˜ธ์ถœํ•œ ๋’ค, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์—ฌํ–‰ ์ผ์ •์„ ์ œ์•ˆํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค:

ํŒŒ๋ฆฌ์—์„œ์˜ ํ•˜๋ฃจ ์ผ์ •:
- 09:00~10:30: ์—ํŽ ํƒ‘ ๋ฐฉ๋ฌธ
- 11:00~12:30: ๋ฃจ๋ธŒ๋ฅด ๋ฐ•๋ฌผ๊ด€ ๋ฐฉ๋ฌธ
- 13:00~14:30: ๋…ธํŠธ๋ฅด๋‹ด ๋Œ€์„ฑ๋‹น ๋ฐฉ๋ฌธ
- 15:30~17:00: ๋ฒ ๋ฅด์‚ฌ์œ  ๊ถ์ „ ๋ฐฉ๋ฌธ
* ์ฃผ์˜: ๋…ธํŠธ๋ฅด๋‹ด ๋Œ€์„ฑ๋‹น์—์„œ ๋ฒ ๋ฅด์‚ฌ์œ  ๊ถ์ „๊นŒ์ง€ ์ด๋™ ์‹œ๊ฐ„์€ ์•ฝ 59๋ถ„์ž…๋‹ˆ๋‹ค.

๋˜ํ•œ, ์ด๋Ÿฌํ•œ ๋„๊ตฌ๋ฅผ Hub์— ๊ณต์œ ํ•˜๋Š” ๋ฐฉ๋ฒ•๋„ ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค:

get_travel_duration.push_to_hub("{your_username}/get-travel-duration-tool")

๊ณต์œ ๋œ ๋„๊ตฌ๋Š” Hub์˜ ์ŠคํŽ˜์ด์Šค์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„ฑ๋Šฅ ๋น„๊ต

SmolAgents๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์˜คํ”ˆ์†Œ์Šค ๋ชจ๋ธ๊ณผ ์ƒ์šฉ ๋ชจ๋ธ์„ ์ด ๋ฒค์น˜๋งˆํฌ๋กœ ๋น„๊ตํ•œ ๊ฒฐ๊ณผ, **์ฝ”๋“œ ๊ธฐ๋ฐ˜ ์—์ด์ „ํŠธ(Code Agents)**๊ฐ€ JSON ๊ธฐ๋ฐ˜ ์—์ด์ „ํŠธ๋ณด๋‹ค ์„ฑ๋Šฅ์ด ๋›ฐ์–ด๋‚œ ๊ฒƒ์œผ๋กœ ๋‚˜ํƒ€๋‚ฌ์Šต๋‹ˆ๋‹ค.

๋” ์ฝ์–ด๋ณด๊ธฐ:rocket:

:scroll: SmolAgents ์†Œ๊ฐœ ๋ธ”๋กœ๊ทธ ๊ธ€ :hugs:

:github: SmolAgents Github ์ €์žฅ์†Œ

๋” ์ฝ์–ด๋ณด๊ธฐ




์ด ๊ธ€์€ GPT ๋ชจ๋ธ๋กœ ์ •๋ฆฌํ•œ ๊ธ€์„ ๋ฐ”ํƒ•์œผ๋กœ ํ•œ ๊ฒƒ์œผ๋กœ, ์›๋ฌธ์˜ ๋‚ด์šฉ ๋˜๋Š” ์˜๋„์™€ ๋‹ค๋ฅด๊ฒŒ ์ •๋ฆฌ๋œ ๋‚ด์šฉ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ๊ด€์‹ฌ์žˆ๋Š” ๋‚ด์šฉ์ด์‹œ๋ผ๋ฉด ์›๋ฌธ๋„ ํ•จ๊ป˜ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”! ์ฝ์œผ์‹œ๋ฉด์„œ ์–ด์ƒ‰ํ•˜๊ฑฐ๋‚˜ ์ž˜๋ชป๋œ ๋‚ด์šฉ์„ ๋ฐœ๊ฒฌํ•˜์‹œ๋ฉด ๋ง๊ธ€๋กœ ์•Œ๋ ค์ฃผ์‹œ๊ธฐ๋ฅผ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค. :hugs:

:pytorch:ํŒŒ์ดํ† ์น˜ ํ•œ๊ตญ ์‚ฌ์šฉ์ž ๋ชจ์ž„:kr:์ด ์ •๋ฆฌํ•œ ์ด ๊ธ€์ด ์œ ์šฉํ•˜์…จ๋‚˜์š”? ํšŒ์›์œผ๋กœ ๊ฐ€์ž…ํ•˜์‹œ๋ฉด ์ฃผ์š” ๊ธ€๋“ค์„ ์ด๋ฉ”์ผ:love_letter:๋กœ ๋ณด๋‚ด๋“œ๋ฆฝ๋‹ˆ๋‹ค! (๊ธฐ๋ณธ์€ Weekly์ง€๋งŒ Daily๋กœ ๋ณ€๊ฒฝ๋„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.)

:gift: ์•„๋ž˜:arrow_lower_right:์ชฝ์— ์ข‹์•„์š”:+1:๋ฅผ ๋ˆŒ๋Ÿฌ์ฃผ์‹œ๋ฉด ์ƒˆ๋กœ์šด ์†Œ์‹๋“ค์„ ์ •๋ฆฌํ•˜๊ณ  ๊ณต์œ ํ•˜๋Š”๋ฐ ํž˜์ด ๋ฉ๋‹ˆ๋‹ค~ :star_struck: