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>