Intro

<aside> ๐Ÿ”ฅ

์šฐ๋ฆฌ๋Š” ์ƒ๊ฐ (Thought) โ†’ ํ–‰๋™ (Action) โ†’ ํ™•์ธ (Observation)์˜ ์‚ฌ์ดํด์ธ AI Agent Workflow์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ด…๋‹ˆ๋‹ค!

</aside>

Body

1. The Core Components

AI Agent Workflow๋Š” ์ƒ๊ฐ (Thought) โ†’ ํ–‰๋™ (Action) โ†’ ํ™•์ธ (Observation)์˜ ์‚ฌ์ดํด์ž…๋‹ˆ๋‹ค! ๊ทธ๋Ÿฌ๋ฏ€๋กœ ๊ฐ ๋‹จ๊ณ„์— ๋Œ€ํ•œ ๋ช…ํ™•ํ•œ ์ •์˜๊ฐ€ ํ•„์š”ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค!

  1. ์ƒ๊ฐ(Thought): Agent์˜ ํ•œ ๋ถ€๋ถ„์ธ LLM์ด ๋‹ค์Œ ๋‹จ๊ณ„์— ๋ฌด์—‡์„ ํ• ์ง€ ์˜์‚ฌ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.
  2. ํ–‰๋™(Action):ย Agent๊ฐ€ ํ–‰๋™์„ ์ทจํ•ฉ๋‹ˆ๋‹ค. ์ด๋•Œ, ๋„๊ตฌ(tool)์™€ ๋„๊ตฌ์— ์‚ฌ์šฉ๋  ์ธ์ž๋“ค(arugments)์„ ํ˜ธ์ถœํ•˜์—ฌ ๋„๊ตฌ๋ฅผ ์ด์šฉํ•œ ํ–‰๋™์„ ํ•ฉ๋‹ˆ๋‹ค.
  3. ํ™•์ธ(Observation):ย ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด์„œ ์–ป์€ ๊ฒฐ๊ณผ๋ฅผ ๋ชจ๋ธ์— ๋ฐ˜์˜ํ•ฉ๋‹ˆ๋‹ค.

2. The Thought โ†’ Action โ†’ Observation Cycle (Workflow)

์„ธ๊ฐ€์ง€ ์š”์†Œ(์ƒ๊ฐ, ํ–‰๋™, ํ™•์ธ)์€ ์ง€์†์ ์œผ๋กœ ๋ฐ˜๋ณต(continuous loop)ํ•ฉ๋‹ˆ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋กœ ํ‘œํ˜„ํ•ด๋ณด์ž๋ฉด, Agent๋Š” while loop๋ฅผ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. while loop๋Š” ๋ชฉ์ ์„ ๋‹ฌ์„ฑํ•˜๊ธฐ ์ „๊นŒ์ง€ ๊ณ„์† ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ๋ชฉ์ ์„ ๊ณ„์† ๋‹ฌ์„ฑํ•˜์ง€ ๋ชปํ•˜๊ณ  ์žˆ๋‹ค๋ฉด Thought โ†’ Action โ†’ Observation โ†’ Thought โ†’ Action โ†’ Observation โ†’ Thought โ†’ โ€ฆ ์ฒ˜๋Ÿผ ๊ณ„์† ๋ฐ˜๋ณตํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

Thought โ†’ Action โ†’ Observation Cycle (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

Thought โ†’ Action โ†’ Observation Cycle (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

2.1. System Message(System Prompt) with Workflow

๋งŽ์€ Agent ํ”„๋ ˆ์ž„์›Œํฌ(frameworks)์—์„œ LLM์ด ์ง€์ผœ์•ผ ํ•  ๊ทœ์น™๊ณผ ๊ฐ€์ด๋“œ๋ผ์ธ์€ system prompt ์•ˆ์— ์ง์ ‘ ๋‚ด์žฅ๋˜์–ด ์žˆ์œผ๋ฉฐ, ์ด๋ฅผ ํ†ตํ•ด ๋ชจ๋“  ์ž‘์—… ์ฃผ๊ธฐ๊ฐ€ ์ผ๊ด€๋œ ๋กœ์ง์„ ๋”ฐ๋ฅด๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, ๋‹ค์Œ๊ณผ ๊ฐ™์€ system prompt๋ฅผ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

system_message="""You are an Ai assistant designed to help users efficiently and accurately. Your primary goal is to provide helpful, precise, and clear responses.

You have access to the following tools:
Tool Name: calculator, Description: Multiply two integers., Arguments: a: int, b: int, Outputs: int

You should think step by step in order to fulfill the objective with a reasoning devided in Thought/Action/Observation that can repeat multiple times if needed.

You should first reflect with 'Thought: {your_thoughts}' on the current situation, then (if necessary), call a tool with the proper JSON formatting 'Action: {JSON_BLOB}', or your print your final answer starting with the prfix 'Final Answer:'
"""

System message์—์„œ ์šฐ๋ฆฌ๋Š” ๋‹ค์Œ์„ ์ •์˜ํ–ˆ์Šต๋‹ˆ๋‹ค.

์ข€๋” ์‰ฌ์šด ์˜ˆ์‹œ๋กœ ์œ„์˜ ํ”„๋กœ์„ธ์Šค๋ฅผ ์ดํ•ดํ•ด๋ด…์‹œ๋‹ค!

2.2. Alfred, the weather Agent

์˜ˆ๋ฅผ ๋“ค์–ด, Alfred๋ผ๊ณ  ํ•˜๋Š” ๋‚ ์”จ Agent๋ฅผ ๋งŒ๋“ค์—ˆ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ด…์‹œ๋‹ค.

User๋Š” Alfred์—๊ฒŒ โ€œWhatโ€™s the current weather in New York?โ€๋ผ๊ณ  ๋ฌผ์–ด๋ด…๋‹ˆ๋‹ค.

A User query (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

A User query (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

Alfred๋Š” User์˜ query(์งˆ๋ฌธ)์— ๋‹ต๋ณ€ํ•˜๊ธฐ ์œ„ํ•ด ๋‚ ์”จ API ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋Œ€๋‹ตํ•˜๊ณ ์ž ํ•ฉ๋‹ˆ๋‹ค.

์ด์ œ ์‹ค์ œ๋กœ ์ƒ๊ฐ (Thought) โ†’ ํ–‰๋™ (Action) โ†’ ํ™•์ธ (Observation) ์‹ธ์ดํด์„ ๋“ค์—ฌ๋‹ค๋ด…์‹œ๋‹ค!

2.3. Thought : Internal Reasoning

์งˆ๋ฌธ์„ ๋ฐ›์€ ์งํ›„, Alfred์˜ **๋‚ด๋ถ€์ ์ธ ์‚ฌ๊ณ  ๊ณผ์ •(internal reasoning)**์€ ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค๊ณ  ์ƒ๊ฐํ•ด๋ด…์‹œ๋‹ค!

Thought (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

Thought (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

โ€œ์‚ฌ์šฉ์ž๋Š” ๋‰ด์š•์˜ ์ตœ์‹  ๋‚ ์”จ ์ •๋ณด๋ฅผ ์›ํ•˜๊ณ  ์žˆ๋‹ค. ๋‚˜๋Š” ๋‚ ์”จ ์ •๋ณด๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค. ๋จผ์ €, ์ตœ์‹  ๋‚ ์”จ ๋ฐ์ดํ„ฐ๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด ๋‚ ์”จ API๋ฅผ ํ˜ธ์ถœํ•ด์•ผ ํ•œ๋‹ค.โ€ โ€œThe user needs current weather information for New York. I have access to a tool that fetches weather data. First, I need to call the weather API to get up-to-date details.โ€

์ด ๋‹จ๊ณ„๋Š” Agent๊ฐ€ ๋ฌธ์ œ๋ฅผ ์„ธ๋ถ€์ ์ธ ๋‹จ๊ณ„๋กœ ๋‚˜๋ˆ„์–ด, ์šฐ์„  ํ•„์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์ง‘ํ•˜๋Š” ๊ณผ์ •์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

2.4. Action : Tool Usage

์‚ฌ๊ณ ๊ณผ์ •์— ๋”ฐ๋ผ Alfred๋Š” get_weather ์ด๋ผ๋Š” ๋‚ ์”จ API๋ฅผ ํ˜ธ์ถœํ•ด์„œ JSON ํ˜•ํƒœ๋กœ ๋œ ์ปค๋งจ๋“œ ๋ช…๋ น์–ด๋“ค๋กœ ์ค€๋น„ํ•œ ๋„๊ตฌ๊ฐ€ ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์•Œ์•„์ฑ•๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ฒซ๋ฒˆ์งธ **ํ–‰๋™(Action)**์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

Action (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

Action (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

์ƒ๊ฐ : ๋‚˜๋Š” ๋‰ด์š•์˜ ํ˜„์žฌ ๋‚ ์”จ๋ฅผ ์ฒดํฌํ•ด์•ผํ•œ ํ•œ๋‹ค. Thought: I need to check the current weather for New York.

   {
     "action": "get_weather",
     "action_input": {
       "location": "New York"
     }
   }

์—ฌ๊ธฐ์„œ ์ด **ํ–‰๋™(action)**์€ ์–ด๋–ค ๋„๊ตฌ๋ฅผ ๋ถˆ๋Ÿฌ์˜ฌ์ง€ ๊ทธ๋ฆฌ๊ณ  ์–ด๋–ค ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์ „๋‹ฌํ•ด์ค„์ง€๋ฅผ ๋ช…ํ™•ํžˆ ๊ตฌ์ฒดํ™”ํ•ฉ๋‹ˆ๋‹ค.

2.5. Observation : Feedback from the Environment

๋„๊ตฌ๋ฅผ ํ˜ธ์ถœํ•œ ํ›„์—, Alfred๋Š” ํ˜ธ์ถœํ•œ ๋„๊ตฌ๋กœ๋ถ€ํ„ฐ ๊ฒฐ๊ณผ๋ฌผ์„ ํ™•์ธํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค. ์ด ๊ฒฐ๊ณผ๋Š” API์—์„œ ๋ฐ›์€ ์‹ค์ œ ๋‚ ์”จ ์ •๋ณด์ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

Observation (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

Observation (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

โ€œํ˜„์žฌ ๋‰ด์š•์˜ ๋‚ ์”จ: ๋ถ€๋ถ„์ ์œผ๋กœ ํ๋ฆผ, ๊ธฐ์˜จ 15ยฐC, ์Šต๋„ 60%.โ€ ****โ€œCurrent weather in New York: partly cloudy, 15ยฐC, 60% humidity.โ€

์ด๋Ÿฌํ•œ ๊ฒฐ๊ณผ๋ฌผ์€ ์ถ”๊ฐ€์ ์ธ ๋งฅ๋ฝ(context)์œผ๋กœ์จ prompt์— ์ถ”๊ฐ€๋ฉ๋‹ˆ๋‹ค. ์ด๊ฒƒ์€ ํ˜„์‹ค ์„ธ๊ณ„์—์„œ์˜ ํ”ผ๋“œ๋ฐฑ์ฒ˜๋Ÿผ ์ž‘๋™ํ•˜๋ฉฐ, ํ–‰๋™์ด ์„ฑ๊ณต์ ์œผ๋กœ ์ˆ˜ํ–‰๋˜์—ˆ๋Š”์ง€ ํ™•์ธํ•˜๊ณ  ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

2.6. Updated thought : Reflecting

๊ฒฐ๊ณผ๋ฌผ์„ ๊ฐ€์ง€๊ณ  Alfred๋Š” ๋‚ด๋ถ€์  ์ถ”๋ก ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค.

Reflection (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

Reflection (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

โ€œ์ด์ œ ๋‰ด์š•์˜ ๋‚ ์”จ ์ •๋ณด๋ฅผ ํ™•๋ณดํ–ˆ์œผ๋‹ˆ, ์‚ฌ์šฉ์ž์—๊ฒŒ ์ œ๊ณตํ•  ๋‹ต๋ณ€์„ ์ค€๋น„ํ•  ์ˆ˜ ์žˆ๋‹ค.โ€ โ€œNow that I have the weather data for New York, I can compile an answer for the user.โ€

2.7. Final Action

์ด์ œ Alfred๋Š” ์šฐ๋ฆฌ๊ฐ€ ๋ฏธ๋ฆฌ ์ง€์ •ํ•œ ํ˜•์‹์— ๋”ฐ๋ผ ์ตœ์ข… ๋‹ต๋ณ€์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค

final action : response (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

final action : response (์ถœ์ฒ˜ : https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure)

์‚ฌ๊ณ  ๊ณผ์ •(Thought): ๋‚ ์”จ ์ •๋ณด๋ฅผ ํ™•๋ณดํ–ˆ๋‹ค. ํ˜„์žฌ ๋‰ด์š• ๋‚ ์”จ๋Š” ๋ถ€๋ถ„์ ์œผ๋กœ ํ๋ฆผ, ๊ธฐ์˜จ 15ยฐC, ์Šต๋„ 60%์ด๋‹ค.

์ตœ์ข… ๋‹ต๋ณ€(Final answer): ํ˜„์žฌ ๋‰ด์š• ๋‚ ์”จ๋Š” ๋ถ€๋ถ„์ ์œผ๋กœ ํ๋ฆผ์ด๋ฉฐ, ๊ธฐ์˜จ์€ 15ยฐC, ์Šต๋„๋Š” 60%์ž…๋‹ˆ๋‹ค.

์ด final action์œผ๋กœ User๋Š” response(์‘๋‹ต)์„ ์ „๋‹ฌ๋ฐ›๊ฒŒ ๋˜๋ฉฐ, ํ•˜๋‚˜์˜ ์‚ฌ์ดํด์ด ์™„๋ฃŒ๋ฉ๋‹ˆ๋‹ค.

Conclusion

์œ„์˜ ์˜ˆ์‹œ๋ฅผ ํ†ตํ•ด ์•Œ ์ˆ˜ ์žˆ๋Š” ์ ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  1. ์—์ด์ „ํŠธ๋Š” ๋ชฉํ‘œ๊ฐ€ ๋‹ฌ์„ฑ๋  ๋•Œ๊นŒ์ง€ ๋ฐ˜๋ณต์  ์‚ฌ์ดํด์„ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค

    Alfred์˜ ํ”„๋กœ์„ธ์Šค๋Š” **๋ฐ˜๋ณต์ (cyclical)**์ž…๋‹ˆ๋‹ค. ๋จผ์ € ์‚ฌ๊ณ (Thought) ๊ณผ์ •์„ ์‹œ์ž‘ํ•˜๊ณ , **๋„๊ตฌ ํ˜ธ์ถœ์„ ํ†ตํ•ด ํ–‰๋™(Action)**์„ ํ•˜๊ณ  ๊ทธ ๊ฒฐ๊ณผ๋ฌผ์„ ํ™•์ธ(Observation)ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ๋ฐ˜ํ™˜๋œ ๊ฒฐ๊ณผ๋ฌผ์ด ์˜ค๋ฅ˜์ด๊ฑฐ๋‚˜ ๋ถˆ์ถฉ๋ถ„ํ•œ ์ •๋ณด์˜€๋‹ค๋ฉด, Alfred๋Š” ๋‹ค์‹œ ์ด ์‚ฌ์ดํด์„ ๋ฐ˜๋ณตํ•˜์—ฌ ๋” ์ ์ ˆํ•œ ์ ‘๊ทผ๋ฒ•์„ ์ฐพ์•˜์„ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

  2. ๋„๊ตฌ์˜ ํ†ตํ•ฉ(Tool Integration)

    ๋‚ ์”จ API์™€ ๊ฐ™์€ ๋„๊ตฌ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋Šฅ๋ ฅ ๋•๋ถ„์— Alfred๋Š” ๊ณ ์ •๋œ(static) ์ง€์‹์— ๋จธ๋ฌด๋ฅด์ง€ ์•Š๊ณ , ์‹ค์‹œ๊ฐ„ ๋ฐ์ดํ„ฐ๋ฅผ ๋ฐ›์•„์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋Š” ๋งŽ์€ AI ์—์ด์ „ํŠธ๊ฐ€ ๋ฐ˜๋“œ์‹œ ๊ฐ–์ถฐ์•ผ ํ•˜๋Š” ์ค‘์š”ํ•œ ํŠน์ง•์ž…๋‹ˆ๋‹ค.

  3. ๋™์  ์ ์‘(Dynamic Adaptation)

    ๊ฐ ๋ฐ˜๋ณต ํšŒ์ฐจ์— ์—์ด์ „ํŠธ๊ฐ€ ์ตœ์‹  ์ •๋ณด(observations)๋ฅผ ์‚ฌ๊ณ  ๊ณผ์ •(thought)์— ์ฆ‰์‹œ ๋ฐ˜์˜ํ•  ์ˆ˜ ์žˆ๋„๋ก ํ•ด์ค๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด ์—์ด์ „ํŠธ๋Š” ์ •ํ™•ํ•˜๊ณ  ์ตœ์‹  ์ •๋ณด์— ๊ธฐ๋ฐ˜ํ•œ ์ตœ์ข… ๋‹ต๋ณ€์„ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค.

์ด๋Ÿฌํ•œ ์˜ˆ์‹œ๋Š” ReAct cycle์˜ ํ•ต์‹ฌ ๊ฐœ๋…์„ ๋ช…ํ™•ํžˆ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค. ์ฆ‰, ์‚ฌ๊ณ (Thought), ํ–‰๋™(Action), ๊ทธ๋ฆฌ๊ณ  ํ™•์ธ (Observation) ๊ฐ„์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ํ†ตํ•ด AI Agent๋Š” ๋ณต์žกํ•œ ์ž‘์—…์„ ์ ์ง„์ ์œผ๋กœ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ด ์›๋ฆฌ๋ฅผ ์ดํ•ดํ•˜๊ณ  ์ ์šฉํ•˜๋ฉด, ์ฃผ์–ด์ง„ ์ž‘์—…์— ๋Œ€ํ•ด ๋‹จ์ˆœํžˆ ์ถ”๋ก ํ•˜๋Š” ๊ฒƒ์„ ๋„˜์–ด ์™ธ๋ถ€์˜ ๋„๊ตฌ๋ฅผ ํšจ๊ณผ์ ์œผ๋กœ ํ™œ์šฉํ•˜๊ณ , ํ™˜๊ฒฝ(environmental)์œผ๋กœ๋ถ€ํ„ฐ์˜ ํ”ผ๋“œ๋ฐฑ์„ ์ง€์†์ ์œผ๋กœ ๋ฐ˜์˜ํ•˜์—ฌ ์ •ํ™•ํ•œ ๋‹ต๋ณ€์„ ์ œ๊ณตํ•˜๋Š” AI Agent๋ฅผ ์„ค๊ณ„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค!


โฌ…๏ธย ์ด์ „ ํŽ˜์ด์ง€

1.5. What are Tools?

โžก๏ธย ๋‹ค์Œ ํŽ˜์ด์ง€

1.7. Thought, Internal Reasoning and the Re-Act Approach

Reference

https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure

<aside>

Topics

1. Introduction to Agents

1.1. Introduction

1.2. What is Agent?

1.3. What are LLMs?

1.4. Messages and Special Tokens

1.5. What are Tools?

1.6. Understanding AI Agents through the Thought-Action-Observation Cycle

1.7. Thought, Internal Reasoning and the Re-Act Approach

1.8. Actions: Enabling the Agent to Engage with Its Environment

1.9. Observe: Integrating Feedback to Reflect and Adapt

</aside>