<aside> ๐ฅ
์ฐ๋ฆฌ๋ ์๊ฐ (Thought) โ ํ๋ (Action) โ ํ์ธ (Observation)
์ ์ฌ์ดํด์ธ AI Agent Workflow์ ๋ํด์ ์์๋ด
๋๋ค!
</aside>
AI Agent Workflow๋ ์๊ฐ (Thought) โ ํ๋ (Action) โ ํ์ธ (Observation)
์ ์ฌ์ดํด์
๋๋ค! ๊ทธ๋ฌ๋ฏ๋ก ๊ฐ ๋จ๊ณ์ ๋ํ ๋ช
ํํ ์ ์๊ฐ ํ์ํ ๊ฒ์
๋๋ค!
์ธ๊ฐ์ง ์์(์๊ฐ, ํ๋, ํ์ธ)์ ์ง์์ ์ผ๋ก ๋ฐ๋ณต(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)
๋ง์ 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์์ ์ฐ๋ฆฌ๋ ๋ค์์ ์ ์ํ์ต๋๋ค.
์ข๋ ์ฌ์ด ์์๋ก ์์ ํ๋ก์ธ์ค๋ฅผ ์ดํดํด๋ด ์๋ค!
์๋ฅผ ๋ค์ด, 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)
Alfred๋ User์ query(์ง๋ฌธ)์ ๋ต๋ณํ๊ธฐ ์ํด ๋ ์จ API ๋๊ตฌ๋ฅผ ์ฌ์ฉํ์ฌ ๋๋ตํ๊ณ ์ ํฉ๋๋ค.
์ด์ ์ค์ ๋ก ์๊ฐ (Thought) โ ํ๋ (Action) โ ํ์ธ (Observation)
์ธ์ดํด์ ๋ค์ฌ๋ค๋ด
์๋ค!
์ง๋ฌธ์ ๋ฐ์ ์งํ, Alfred์ **๋ด๋ถ์ ์ธ ์ฌ๊ณ ๊ณผ์ (internal reasoning)**์ ๋ค์๊ณผ ๊ฐ๋ค๊ณ ์๊ฐํด๋ด ์๋ค!
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๊ฐ ๋ฌธ์ ๋ฅผ ์ธ๋ถ์ ์ธ ๋จ๊ณ๋ก ๋๋์ด, ์ฐ์ ํ์ํ ๋ฐ์ดํฐ๋ฅผ ์์งํ๋ ๊ณผ์ ์ ๋ณด์ฌ์ค๋๋ค.
์ฌ๊ณ ๊ณผ์ ์ ๋ฐ๋ผ Alfred๋ get_weather
์ด๋ผ๋ ๋ ์จ API๋ฅผ ํธ์ถํด์ JSON ํํ๋ก ๋ ์ปค๋งจ๋ ๋ช
๋ น์ด๋ค๋ก ์ค๋นํ ๋๊ตฌ๊ฐ ์๋ค๋ ๊ฒ์ ์์์ฑ๋๋ค. ์๋ฅผ ๋ค์ด, ์ฒซ๋ฒ์งธ **ํ๋(Action)**์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
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)**์ ์ด๋ค ๋๊ตฌ๋ฅผ ๋ถ๋ฌ์ฌ์ง ๊ทธ๋ฆฌ๊ณ ์ด๋ค ํ๋ผ๋ฏธํฐ๋ฅผ ์ ๋ฌํด์ค์ง๋ฅผ ๋ช ํํ ๊ตฌ์ฒดํํฉ๋๋ค.
get_weather
{"locationโ : โNew Yorkโ}
๋๊ตฌ๋ฅผ ํธ์ถํ ํ์, Alfred๋ ํธ์ถํ ๋๊ตฌ๋ก๋ถํฐ ๊ฒฐ๊ณผ๋ฌผ์ ํ์ธํ๊ฒ ๋ฉ๋๋ค. ์ด ๊ฒฐ๊ณผ๋ API์์ ๋ฐ์ ์ค์ ๋ ์จ ์ ๋ณด์ผ ์ ์์ต๋๋ค.
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์ ์ถ๊ฐ๋ฉ๋๋ค. ์ด๊ฒ์ ํ์ค ์ธ๊ณ์์์ ํผ๋๋ฐฑ์ฒ๋ผ ์๋ํ๋ฉฐ, ํ๋์ด ์ฑ๊ณต์ ์ผ๋ก ์ํ๋์๋์ง ํ์ธํ๊ณ ํ์ํ ์ ๋ณด๋ฅผ ์ ๊ณตํฉ๋๋ค.
๊ฒฐ๊ณผ๋ฌผ์ ๊ฐ์ง๊ณ Alfred๋ ๋ด๋ถ์ ์ถ๋ก ์ ๋ค์๊ณผ ๊ฐ์ด ์ ๋ฐ์ดํธํฉ๋๋ค.
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.โ
์ด์ Alfred๋ ์ฐ๋ฆฌ๊ฐ ๋ฏธ๋ฆฌ ์ง์ ํ ํ์์ ๋ฐ๋ผ ์ต์ข ๋ต๋ณ์ ์์ฑํฉ๋๋ค
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(์๋ต)์ ์ ๋ฌ๋ฐ๊ฒ ๋๋ฉฐ, ํ๋์ ์ฌ์ดํด์ด ์๋ฃ๋ฉ๋๋ค.
์์ ์์๋ฅผ ํตํด ์ ์ ์๋ ์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
์์ด์ ํธ๋ ๋ชฉํ๊ฐ ๋ฌ์ฑ๋ ๋๊น์ง ๋ฐ๋ณต์ ์ฌ์ดํด์ ์ํํฉ๋๋ค
Alfred์ ํ๋ก์ธ์ค๋ **๋ฐ๋ณต์ (cyclical)**์ ๋๋ค. ๋จผ์ ์ฌ๊ณ (Thought) ๊ณผ์ ์ ์์ํ๊ณ , **๋๊ตฌ ํธ์ถ์ ํตํด ํ๋(Action)**์ ํ๊ณ ๊ทธ ๊ฒฐ๊ณผ๋ฌผ์ ํ์ธ(Observation)ํฉ๋๋ค. ๋ง์ฝ ๋ฐํ๋ ๊ฒฐ๊ณผ๋ฌผ์ด ์ค๋ฅ์ด๊ฑฐ๋ ๋ถ์ถฉ๋ถํ ์ ๋ณด์๋ค๋ฉด, Alfred๋ ๋ค์ ์ด ์ฌ์ดํด์ ๋ฐ๋ณตํ์ฌ ๋ ์ ์ ํ ์ ๊ทผ๋ฒ์ ์ฐพ์์ ๊ฒ์ ๋๋ค.
๋๊ตฌ์ ํตํฉ(Tool Integration)
๋ ์จ API์ ๊ฐ์ ๋๊ตฌ๋ฅผ ํธ์ถํ๋ ๋ฅ๋ ฅ ๋๋ถ์ Alfred๋ ๊ณ ์ ๋(static) ์ง์์ ๋จธ๋ฌด๋ฅด์ง ์๊ณ , ์ค์๊ฐ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ฌ ์ ์์ต๋๋ค. ์ด๋ ๋ง์ AI ์์ด์ ํธ๊ฐ ๋ฐ๋์ ๊ฐ์ถฐ์ผ ํ๋ ์ค์ํ ํน์ง์ ๋๋ค.
๋์ ์ ์(Dynamic Adaptation)
๊ฐ ๋ฐ๋ณต ํ์ฐจ์ ์์ด์ ํธ๊ฐ ์ต์ ์ ๋ณด(observations)๋ฅผ ์ฌ๊ณ ๊ณผ์ (thought)์ ์ฆ์ ๋ฐ์ํ ์ ์๋๋ก ํด์ค๋๋ค. ์ด๋ฅผ ํตํด ์์ด์ ํธ๋ ์ ํํ๊ณ ์ต์ ์ ๋ณด์ ๊ธฐ๋ฐํ ์ต์ข ๋ต๋ณ์ ์์ฑํฉ๋๋ค.
์ด๋ฌํ ์์๋ ReAct cycle์ ํต์ฌ ๊ฐ๋ ์ ๋ช ํํ ๋ณด์ฌ์ค๋๋ค. ์ฆ, ์ฌ๊ณ (Thought), ํ๋(Action), ๊ทธ๋ฆฌ๊ณ ํ์ธ (Observation) ๊ฐ์ ์ํธ์์ฉ์ ํตํด AI Agent๋ ๋ณต์กํ ์์ ์ ์ ์ง์ ์ผ๋ก ํด๊ฒฐํ ์ ์์ต๋๋ค.
์ด ์๋ฆฌ๋ฅผ ์ดํดํ๊ณ ์ ์ฉํ๋ฉด, ์ฃผ์ด์ง ์์ ์ ๋ํด ๋จ์ํ ์ถ๋ก ํ๋ ๊ฒ์ ๋์ด ์ธ๋ถ์ ๋๊ตฌ๋ฅผ ํจ๊ณผ์ ์ผ๋ก ํ์ฉํ๊ณ , ํ๊ฒฝ(environmental)์ผ๋ก๋ถํฐ์ ํผ๋๋ฐฑ์ ์ง์์ ์ผ๋ก ๋ฐ์ํ์ฌ ์ ํํ ๋ต๋ณ์ ์ ๊ณตํ๋ AI Agent๋ฅผ ์ค๊ณํ ์ ์์ต๋๋ค!
โฌ ๏ธย ์ด์ ํ์ด์ง
โก๏ธย ๋ค์ ํ์ด์ง
1.7. Thought, Internal Reasoning and the Re-Act Approach
https://huggingface.co/learn/agents-course/en/unit1/agent-steps-and-structure
<aside>
1.4. Messages and Special Tokens
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>