[AI Paper] ๐ ReAct: Synergizing Reasoning and Acting in Language Models
๐ ReAct: Synergizing Reasoning and Acting in Language Models
๐ ๋ฉํ ์ ๋ณด
| ํญ๋ชฉ | ๋ด์ฉ |
|---|---|
| ์ ์ | Shunyu Yao, Jeffrey Zhao, Dian Yu, Nan Du, Izhak Shafran, Karthik Narasimhan, Yuan Cao |
| ์์ | Princeton University (Department of Computer Science), Google Research (Brain Team) |
| ๋ฐํ์ฒ | ICLR 2023 (International Conference on Learning Representations) |
| ์ฐ๋ | 2022๋ 10์ (arXiv), 2023๋ (ICLR ๋ฐํ) |
| ์์ | ICLR 2023 Notable Top 5% Paper, Oral Presentation |
| arXiv | https://arxiv.org/abs/2210.03629 |
| OpenReview | https://openreview.net/forum?id=WE_vluYUL-X |
| GitHub | https://github.com/ysymyth/ReAct |
| ํ๋ก์ ํธ ํ์ด์ง | https://react-lm.github.io/ |
๐ฏ ํ์ค ์์ฝ
LLM์ด ์ถ๋ก (Reasoning)๊ณผ ํ๋(Acting)์ ๊ต์ฐจ(interleaved) ๋ฐฉ์์ผ๋ก ์์ฑํ๋๋ก ํ์ฌ, ๋์ ์ถ๋ก ์ ํตํ ํ๋ ๊ณํ ์๋ฆฝ๊ณผ ์ธ๋ถ ํ๊ฒฝ๊ณผ์ ์ํธ์์ฉ์ ํตํ ์ ๋ณด ์์ง์ ๋์์ ๊ฐ๋ฅํ๊ฒ ํ AI Agent์ ํต์ฌ ํ๋ ์์ํฌ
๐ ์ฐ๊ตฌ ๋ฐฐ๊ฒฝ ๋ฐ ๋๊ธฐ
๊ธฐ์กด ๋ฌธ์ ์
- Reasoning๊ณผ Acting์ ๋ถ๋ฆฌ๋ ์ฐ๊ตฌ
- LLM์ ์ถ๋ก ๋ฅ๋ ฅ(์: Chain-of-Thought prompting)๊ณผ ํ๋ ๋ฅ๋ ฅ(์: action plan generation)์ด ๋ณ๊ฐ์ ์ฐ๊ตฌ ์ฃผ์ ๋ก ๋ค๋ค์ ธ ์ด
- ๋ ๋ฅ๋ ฅ ๊ฐ์ ์๋์ง ํจ๊ณผ๋ฅผ ํ์ฉํ์ง ๋ชปํจ
- Chain-of-Thought (CoT)์ ํ๊ณ
- ์ธ๋ถ ์ธ๊ณ์ ๋ํ ์ ๊ทผ ๋ถ๊ฐ
- ์ง์ ์ ๋ฐ์ดํธ ๋ถ๊ฐ๋ฅ
- ํ๊ฐ(Hallucination) ๋ฌธ์ : ๋
ผ๋ฆฌ์ ์ผ๋ก ๋ค๋ฆฌ์ง๋ง ์ฌ์ค๊ณผ ๋ค๋ฅธ ๋ด์ฉ ์์ฑ
- HotpotQA์์ CoT์ ํ๊ฐ์ผ๋ก ์ธํ false positive rate์ด ReAct ๋๋น 2๋ฐฐ ์ด์ (14% vs 6%)
- CoT์ ์ฃผ์ ์คํจ ์์ธ ์ค 56%๊ฐ ํ๊ฐ์ผ๋ก ์ธํ ๊ฒ
- ์ค๋ฅ ์ ํ(Error Propagation): ์ด๊ธฐ ์ถ๋ก ์ค๋ฅ๊ฐ ํ์ ๋จ๊ณ๋ก ์ ํ
- Action-only ์ ๊ทผ๋ฒ์ ํ๊ณ
- ๊ณ ์์ค ๋ชฉํ ์ถ์ ๋ฐ ๊ณํ ์กฐ์ ๋ฅ๋ ฅ ๋ถ์กฑ
- ์์ธ ์ํฉ ์ฒ๋ฆฌ ์ด๋ ค์
- ํ๋์ ๊ทผ๊ฑฐ๋ ์๋ ํ์ ๋ถ๊ฐ
- ๋ชฉํ๋ฅผ ํ์ ๋ชฉํ๋ก ์ ์ ํ ๋ถํดํ์ง ๋ชปํจ
์ ์ด ์ฐ๊ตฌ๊ฐ ํ์ํ๊ฐ?
- ์ธ๊ฐ์ ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ์: ์ถ๋ก ๊ณผ ํ๋์ด ๊ธด๋ฐํ๊ฒ ์ฐ๊ฒฐ
- ์: ์๋ฆฌํ ๋ ๋ ์ํผ๋ฅผ ์ถ๋ก ํ๋ฉด์(reason to act) ๋์์ ์ฌ๋ฃ ์ํ๋ฅผ ํ์ธํ๋ฉฐ ๊ณํ ์กฐ์ (act to reason)
- ๋ ๋ค๋ฅธ ์: “์ํ ์์ ์์ผ๋ ์๋์ ํ์ธํด๋ด์ผ๊ฒ ๋ค”๋ ์๊ฐ(์ถ๋ก ) -> ์๋ ์ด๊ธฐ(ํ๋) -> ๊ฒฐ๊ณผ ํ์ธ(๊ด์ฐฐ)
- LLM๋ ์ด๋ฌํ ์ธ๊ฐ๊ณผ ์ ์ฌํ ์๋์ง์ ์ ๊ทผ์ด ํ์
๐ก ํต์ฌ ์์ด๋์ด
ReAct = Reasoning + Acting
ReAct๋ LLM์ด ์ถ๋ก ํธ๋ ์ด์ค(reasoning traces)์ ํ์คํฌ๋ณ ํ๋(task-specific actions)์ ์ธํฐ๋ฆฌ๋น(interleaving) ๋ฐฉ์์ผ๋ก ์์ฑํ๋๋ก ํจ.
์๋ฐฉํฅ ์๋์ง
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ReAct Framework โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ Reason to Act Act to Reason โ
โ โโโโโโโโโโโโโ โโโโโโโโโโโโโ โ
โ โข ๋์ ์ถ๋ก ์ผ๋ก ๊ณ ์์ค ๊ณํ ์๋ฆฝ โข ์ธ๋ถ ํ๊ฒฝ๊ณผ ์ํธ์์ฉ โ
โ โข ๊ณํ ์ ์ง ๋ฐ ์กฐ์ โข ์ถ๊ฐ ์ ๋ณด ํ๋ โ
โ โข ์์ธ ์ํฉ ์ฒ๋ฆฌ โข ์ถ๋ก ์ ์ ์ ๋ณด ๋ฐ์ โ
โ โ
โ โโโโโโโโ โโโโโโโโ โโโโโโโโโโโโ โ
โ โThoughtโโโโโโโโถโActionโโโโโโโโถโObservationโ โ
โ โโโโโโโโ โโโโโโโโ โโโโโโโโโโโโ โ
โ โฒ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ (๋ฐ๋ณต) โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Thought-Action-Observation ๋ฃจํ
| ๊ตฌ์ฑ์์ | ์ญํ | ํน์ง | ์์ |
|---|---|---|---|
| Thought | ์ถ๋ก | ์ธ๋ถ ํ๊ฒฝ์ ์ํฅ ์์, ๋ด๋ถ ์ถ๋ก ๋ง | “Colorado orogeny์ ๋๋ถ ๊ตฌ์ญ์ ์ฐพ์๋ด์ผ๊ฒ ๋ค” |
| Action | ํ๋ | ์ธ๋ถ ํ๊ฒฝ๊ณผ ์ํธ์์ฉ | Search[High Plains], Lookup[eastern sector] |
| Observation | ๊ด์ฐฐ | ํ๋ ๊ฒฐ๊ณผ ์์ | “High Plains๋ ํด๋ฐ 1,800~7,000ft์ ์์น…” |
ํต์ฌ ์ฐจ๋ณ์
- Reasoning traces๋ ์ธ๋ถ ํ๊ฒฝ์ ์ํฅ์ ์ฃผ์ง ์์ (์์ ๋ด๋ถ ์ถ๋ก )
- Actions๋ ์ธ๋ถ ํ๊ฒฝ๊ณผ ์ํธ์์ฉํ์ฌ observation feedback์ ๋ฐ์
- ๋ ๊ฐ์ง๊ฐ ๊ต์ฐจ(interleaved)๋๋ฉด์ ์๋์ง ํจ๊ณผ ๋ฐ์
๐๏ธ ์ํคํ ์ฒ / ๋ฐฉ๋ฒ๋ก
์์คํ ๊ตฌ์กฐ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ReAct System โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Prompt โ โ Frozen LLM โ โ
โ โ (Few-shot โโโโโโถโ (PaLM-540B / GPT-3 ๋ฑ) โ โ
โ โ Exemplars) โ โ โ โ
โ โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Autoregressive Generation โ โ
โ โ โโโโโโโโโโโ โโโโโโโโโโโโโโโ โ โ
โ โ โ Thought โ or โ Action โ โ โ
โ โ โโโโโโโโโโโ โโโโโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ โ
โ โผ โผ โ
โ Thought์ธ ๊ฒฝ์ฐ Action์ธ ๊ฒฝ์ฐ โ
โ (์ปจํ
์คํธ์ (์ธ๋ถ ํ๊ฒฝ ํธ์ถ) โ
โ ์ถ๊ฐ๋ง) โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ External Environmentโ โ
โ โ - Wikipedia API โ โ
โ โ - ALFWorld โ โ
โ โ - WebShop โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Observation โ โ
โ โ (์ปจํ
์คํธ์ ์ถ๊ฐ) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
ReAct ํ๋กฌํํธ ๊ตฌ์กฐ
[Few-shot ์์๋ค]
Question: {์ง๋ฌธ}
Thought 1: {ํ์ฌ ์ํฉ ๋ถ์ ๋ฐ ๊ณํ}
Action 1: {์ํํ ์ก์
}[{ํ๋ผ๋ฏธํฐ}]
Observation 1: {์ก์
๊ฒฐ๊ณผ}
Thought 2: {๊ด์ฐฐ ๊ฒฐ๊ณผ ๋ถ์ ๋ฐ ๋ค์ ๊ณํ}
Action 2: ...
...
Thought N: {์ต์ข
๋ต๋ณ ๋์ถ ์ถ๋ก }
Action N: Finish[{์ต์ข
๋ต๋ณ}]
์ง์ ์ก์ ํ์ (QA/Fact Verification)
| ์ก์ | ์ค๋ช | ์์ |
|---|---|---|
Search[entity] |
Wikipedia์์ ์ํฐํฐ ๊ฒ์, ์ฒซ 5๋ฌธ์ฅ ๋ฐํ. ์์ผ๋ฉด ์์ 5๊ฐ ์ ์ฌ ์ํฐํฐ ์ ์ | Search[Colorado orogeny] |
Lookup[keyword] |
ํ์ฌ ํ์ด์ง์์ ํค์๋๊ฐ ํฌํจ๋ ๋ค์ ๋ฌธ์ฅ ๋ฐํ (Ctrl+F ์๋ฎฌ๋ ์ด์ ) | Lookup[eastern sector] |
Finish[answer] |
์ต์ข ๋ต๋ณ ์ ์ถ ๋ฐ ํ์คํฌ ์ข ๋ฃ | Finish[1,800 to 7,000 ft] |
์ค์ ์์ (HotpotQA)
Question: Colorado orogeny์ ๋๋ถ ๊ตฌ์ญ์ด ํ์ฅ๋๋ ์ง์ญ์ ๊ณ ๋ ๋ฒ์๋?
Thought 1: Colorado orogeny๋ฅผ ๊ฒ์ํ์ฌ ๋๋ถ ๊ตฌ์ญ ์ ๋ณด๋ฅผ ์ฐพ์์ผ ํ๋ค.
Action 1: Search[Colorado orogeny]
Observation 1: The Colorado orogeny was an episode of mountain building...
(๋๋ถ ๊ตฌ์ญ์ ๋ํ ์ง์ ์ ์ธ๊ธ ์์)
Thought 2: ๋๋ถ ๊ตฌ์ญ์ ๋ํ ์ธ๊ธ์ด ์๋ค. ๋๋ถ ๊ตฌ์ญ์ lookupํด์ผ ํ๋ค.
Action 2: Lookup[eastern sector]
Observation 2: (Result 1/1) The eastern sector extends into the High Plains
and is called the Central Plains orogeny.
Thought 3: ๋๋ถ ๊ตฌ์ญ์ด High Plains๋ก ํ์ฅ๋๋ค. High Plains์ ๊ณ ๋๋ฅผ ๊ฒ์ํด์ผ ํ๋ค.
Action 3: Search[High Plains]
Observation 3: High Plains refers to one of the two distinct land regions...
rise in elevation from around 1,800 to 7,000 ft.
Thought 4: High Plains์ ๊ณ ๋ ๋ฒ์๋ 1,800~7,000 ft์ด๋ค. ์ด๊ฒ์ด ๋ต์ด๋ค.
Action 4: Finish[1,800 to 7,000 ft]
Interactive Decision Making ์์ (ALFWorld)
Task: put a clean apple in the fridge.
Thought: To complete this task, I need to find an apple, clean it, then put it in the fridge.
Action: go to countertop 1
Observation: On the countertop 1, you see an apple 1.
Thought: I found an apple. Now I need to take it.
Action: take apple 1 from countertop 1
Observation: You pick up the apple 1.
Thought: I have the apple. Now I need to clean it at the sink.
Action: go to sinkbasin 1
Observation: On the sinkbasin 1, you see nothing.
Thought: I'm at the sink. Let me clean the apple.
Action: clean apple 1 with sinkbasin 1
Observation: You clean the apple 1 using the sinkbasin 1.
Thought: The apple is clean. Now I need to put it in the fridge.
Action: go to fridge 1
Observation: The fridge 1 is closed.
Action: open fridge 1
Observation: You open the fridge 1.
Action: put apple 1 in/on fridge 1
Observation: You put the apple 1 in/on the fridge 1.
์๊ณ ๋ฆฌ์ฆ Pseudo Code
def react_agent(question, few_shot_examples, llm, environment):
"""
ReAct Agent ์๊ณ ๋ฆฌ์ฆ
Args:
question: ํด๊ฒฐํ ์ง๋ฌธ/ํ์คํฌ
few_shot_examples: ์ธ์ปจํ
์คํธ ํ์ต์ฉ ์์ ๊ถค์ ๋ค
llm: ์ฌ์ ํ์ต๋ ์ธ์ด ๋ชจ๋ธ (frozen, PaLM-540B)
environment: ์ธ๋ถ ํ๊ฒฝ (Wikipedia API, ALFWorld ๋ฑ)
Returns:
final_answer: ์ต์ข
๋ต๋ณ
"""
# ํ๋กฌํํธ ์ด๊ธฐํ
context = few_shot_examples + f"\nQuestion: {question}\n"
step = 1
while True:
# 1. Thought ์์ฑ (์ถ๋ก ๋จ๊ณ)
thought = llm.generate(
context + f"Thought {step}:",
stop_tokens=["Action"]
)
context += f"Thought {step}: {thought}\n"
# 2. Action ์์ฑ (ํ๋ ๊ฒฐ์ )
action = llm.generate(
context + f"Action {step}:",
stop_tokens=["Observation"]
)
context += f"Action {step}: {action}\n"
# 3. Action ํ์ฑ ๋ฐ ์คํ
action_type, action_arg = parse_action(action)
# ์ข
๋ฃ ์กฐ๊ฑด ์ฒดํฌ
if action_type == "finish":
return action_arg
# 4. ํ๊ฒฝ๊ณผ ์ํธ์์ฉํ์ฌ Observation ํ๋
observation = environment.execute(action_type, action_arg)
context += f"Observation {step}: {observation}\n"
step += 1
# ์ต๋ ์คํ
๋๋ฌ ์ ์ข
๋ฃ
if step > MAX_STEPS:
return "Unable to find answer"
def parse_action(action_string):
"""
์ก์
๋ฌธ์์ด์ ํ์ฑํ์ฌ ํ์
๊ณผ ์ธ์ ์ถ์ถ
์: "search[Colorado orogeny]" -> ("search", "Colorado orogeny")
"""
match = re.match(r"(\w+)\[(.+)\]", action_string)
if match:
return match.group(1), match.group(2)
return None, None
4๊ฐ์ง ํ๋กฌํํ ๋ฐฉ๋ฒ ๋น๊ต
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Prompting Methods Comparison โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ (a) Standard: Question โ Answer โ
โ (์ง์ ๋ต๋ณ, ์ถ๋ก ์์) โ
โ โ
โ (b) CoT: Question โ Thoughtโ โ ... โ Answer โ
โ (Reason (๋ด๋ถ ์ถ๋ก ๋ง, ์ธ๋ถ ์ํธ์์ฉ ์์) โ
โ Only) โ
โ โ
โ (c) Act-only: Question โ Actionโ โ Obsโ โ ... โ Answer โ
โ (ํ๋๋ง, ์ถ๋ก ์์) โ
โ โ
โ (d) ReAct: Question โ Thoughtโ โ Actionโ โ Obsโ โ โ
โ Thoughtโ โ Actionโ โ Obsโ โ ... โ
โ (์ถ๋ก + ํ๋ ๊ต์ฐจ) โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ ์คํ ๋ฐ ๊ฒฐ๊ณผ
์ฌ์ฉ ๋ชจ๋ธ ๋ฐ ์ค์
- Base Model: PaLM-540B (frozen, prompting only)
- Few-shot Examples: 1-6๊ฐ์ in-context ์์
- ๋น๊ต ๋ชจ๋ธ: GPT-3 (text-davinci-002)
๋ฒค์น๋งํฌ ๊ฐ์
| ๋ฒค์น๋งํฌ | ํ์คํฌ ์ ํ | ํ๊ฒฝ | ํ๊ฐ ์งํ |
|---|---|---|---|
| HotpotQA | ๋ค์ค ํ ์ง๋ฌธ ๋ต๋ณ | Wikipedia API | Exact Match (EM) |
| FEVER | ์ฌ์ค ๊ฒ์ฆ (SUPPORTS/REFUTES/NOT ENOUGH INFO) | Wikipedia API | Accuracy |
| ALFWorld | ํ ์คํธ ๊ธฐ๋ฐ ๊ฒ์ | ๊ฐ์ ๊ฐ์ ํ๊ฒฝ | Success Rate |
| WebShop | ์นํ์ด์ง ํ์ ๋ฐ ์ผํ | ์น ์๋ฎฌ๋ ์ดํฐ | Success Rate, Reward |
Knowledge-Intensive Tasks ๊ฒฐ๊ณผ
HotpotQA (Multi-hop Question Answering)
| ๋ฐฉ๋ฒ | Exact Match (EM) | ํน์ง |
|---|---|---|
| Standard | 25.7% | ๋จ์ ๋ต๋ณ ์์ฑ |
| CoT (Chain-of-Thought) | 29.4% | ๋ด๋ถ ์ถ๋ก ๋ง ์ฌ์ฉ |
| Act-only | 25.7% | ํ๋๋ง ์ํ, ์ถ๋ก ์์ |
| ReAct | 27.4% | ์ถ๋ก + ํ๋ ๊ฒฐํฉ |
| ReAct + CoT-SC | 35.1% | ๋ ๋ฐฉ๋ฒ ๊ฒฐํฉ ์ ์ต๊ณ ์ฑ๋ฅ |
Note: CoT๊ฐ HotpotQA์์ ์ฝ๊ฐ ๋์ ์ฑ๋ฅ์ ๋ณด์ด๋, ReAct๋ ํด์ ๊ฐ๋ฅ์ฑ๊ณผ ์ ๋ขฐ์ฑ์์ ์ฐ์
FEVER (Fact Verification)
| ๋ฐฉ๋ฒ | Accuracy | False Positive Rate |
|---|---|---|
| CoT | 56.3% | 14% (ํ๊ฐ์ผ๋ก ์ธํ) |
| Act-only | 58.9% | – |
| ReAct | 60.9% | 6% |
| ReAct + CoT-SC | 64.6% | – |
ReAct๊ฐ FEVER์์ CoT ๋๋น 4.6%p ํฅ์, ํ๊ฐ์ผ๋ก ์ธํ ์ค๋ฅ ๋ํญ ๊ฐ์
Decision Making Tasks ๊ฒฐ๊ณผ
ALFWorld (Text-based Game)
| ๋ฐฉ๋ฒ | Success Rate | Training Data |
|---|---|---|
| BUTLER (IL) | 26% | 10^5 instances |
| BUTLER (IL+RL) | 37% | 10^5 instances |
| Act-only (1-shot) | 45% | 1 example |
| ReAct (1-shot) | 71% | 1 example |
| ReAct (best trial) | 71% | – |
| ReAct (worst trial) | 48% | – |
ReAct๊ฐ ๊ฐํํ์ต/๋ชจ๋ฐฉํ์ต ๋๋น 34%p ์ ๋์ ํฅ์, ํ๋ จ ๋ฐ์ดํฐ ๊ฑฐ์ ๋ถํ์
WebShop (Web Navigation)
| ๋ฐฉ๋ฒ | Success Rate | Reward |
|---|---|---|
| IL (Imitation Learning) | 29.1% | – |
| IL + RL | 30% | – |
| ReAct (1-shot) | 40% | – |
| Human Expert | 50% | – |
ReAct๊ฐ ๊ธฐ์กด ์ต๊ณ ๋ฐฉ๋ฒ ๋๋น 10%p ํฅ์, ์ธ๊ฐ ์์ค(50%)์ ๊ทผ์
์ค๋ฅ ๋ถ์
| ์ค๋ฅ ์ ํ | CoT | ReAct | ์ค๋ช |
|---|---|---|---|
| ํ๊ฐ (Hallucination) | 56% | ๋ฎ์ | CoT์ ์ฃผ์ ์คํจ ์์ธ |
| ๋น์ ๋ณด์ ๊ฒ์ | – | 23% | ReAct์ ์ฃผ์ ์คํจ ์์ธ |
| ์ถ๋ก ์ค๋ฅ | ์ค๊ฐ | ๋ฎ์ | – |
| False Positive Rate | 14% | 6% | ํ๊ฐ์ผ๋ก ์ธํ ์๋ชป๋ ๊ธ์ |
ํต์ฌ ๋ฐ๊ฒฌ
- ํ๊ฐ ๊ฐ์: ReAct๋ CoT ๋๋น ํ๊ฐ์ผ๋ก ์ธํ ์คํจ๋ฅผ ํฌ๊ฒ ๊ฐ์์ํด
- ์ํ ํจ์จ์ฑ: 1-2๊ฐ์ few-shot ์์ ๋ง์ผ๋ก 10^3~10^5๊ฐ ์ธ์คํด์ค๋ก ํ๋ จ๋ IL/RL ๋ฐฉ๋ฒ ๋ฅ๊ฐ
- ReAct + CoT ๊ฒฐํฉ์ด ์ต์ : ๋ด๋ถ ์ง์(CoT)๊ณผ ์ธ๋ถ ์ ๋ณด(ReAct) ๋ชจ๋ ํ์ฉ ๊ฐ๋ฅ
- ๊ฒ์ ํ์ง์ ์ค์์ฑ: ReAct์์ ๋น์ ๋ณด์ ๊ฒ์(non-informative search)์ ์ค๋ฅ์ 23% ์ฐจ์ง
๐ช ๊ฐ์ ๋ฐ ๊ธฐ์ฌ
ํ์ ์ ๊ธฐ์ฌ
- ์๋ก์ด ํจ๋ฌ๋ค์ ์ ์: ์ถ๋ก ๊ณผ ํ๋์ ์๋์ง๋ฅผ ํตํ LLM ์์ด์ ํธ์ ๊ธฐ์ด ํ๋ ์์ํฌ ํ๋ฆฝ
-
ํ๊ฐ ๋ฌธ์ ์ํ: ์ธ๋ถ ์ง์ ๊ธฐ๋ฐ๊ณผ์ ์ํธ์์ฉ์ ํตํด ์ฌ์ค์ ์ ํ์ฑ ํฅ์
-
ํด์ ๊ฐ๋ฅ์ฑ ํฅ์: ์ธ๊ฐ๊ณผ ์ ์ฌํ ๋ฌธ์ ํด๊ฒฐ ๊ถค์ ์์ฑ์ผ๋ก ๋๋ฒ๊น ์ฉ์ด
์ค์ฉ์ ์ฅ์
| ์ฅ์ | ์ค๋ช |
|---|---|
| ํด์ ๊ฐ๋ฅ์ฑ | ๊ฐ ๋จ๊ณ์ ์ถ๋ก ๊ณผ์ ์ด ๋ช ์์ ์ผ๋ก ํํ๋จ |
| ๋๋ฒ๊น ์ฉ์ด | ์ด๋ ๋จ๊ณ์์ ์ค๋ฅ๊ฐ ๋ฐ์ํ๋์ง ์ฝ๊ฒ ํ์ ๊ฐ๋ฅ |
| ํ๊ฐ ๊ฐ์ | ์ธ๋ถ ์ง์ ์์ค์ ์ํธ์์ฉํ์ฌ ์ฌ์ค ํ์ธ |
| ์ค๋ฅ ์ ํ ๋ฐฉ์ง | ์ค๊ฐ ๋จ๊ณ์์ ์ธ๋ถ ํผ๋๋ฐฑ์ผ๋ก ์ค๋ฅ ์์ |
| ๋ฐ์ดํฐ ํจ์จ์ฑ | 1-2๊ฐ์ few-shot ์์๋ง์ผ๋ก ๊ฐ๋ ฅํ ์ฑ๋ฅ |
| ์ ์ฐ์ฑ | ๋ค์ํ ๋๋ฉ์ธ(QA, ๊ฒ์, ์น)์ ์ ์ฉ ๊ฐ๋ฅ |
| ์ ์ด ๊ฐ๋ฅ์ฑ | ์ธ๊ฐ์ด ์ถ๋ก ๊ณผ์ ์ ๊ฐ์ ํ์ฌ ์์ ๊ฐ๋ฅ |
Human-in-the-Loop ๊ฐ๋ฅ์ฑ
- ํ๊ฐ์ด ๋ฐ์ํ ๋ฌธ์ฅ์ ์ธ๊ฐ์ด ์์ ํ๋ฉด ๋ชจ๋ธ์ด ์ด๋ฅผ ๋ฐ์ํ์ฌ ์ฌ๋ฐ๋ฅธ ๋ต์ ๋์ถ
- ์์์ Thought๋ง ์์ ํ๋ฉด ๋๋ฏ๋ก ์ธ๊ฐ-๊ธฐ๊ณ ํ์ ์ ํจ๊ณผ์
์ค๋ฌด์ ์ํฅ
- LangChain Agents์ ๊ธฐ๋ฐ: ์์ฉ AI ์์ด์ ํธ ํ๋ ์์ํฌ์ ํต์ฌ ๊ตฌ์กฐ๋ก ์ฑํ
- AI Agent ์ฐ๊ตฌ์ ๊ธฐ์ด: ํ์ ์ฐ๊ตฌ(Reflexion, ReSpAct, AutoGPT ๋ฑ)์ foundation
- ์ฐ์ ํ์คํ: Tool-calling AI ์์คํ ์ de facto ํ์ค ํจํด์ผ๋ก ์๋ฆฌ์ก์
โ ๏ธ ํ๊ณ์ ๋ฐ ํฅํ ์ฐ๊ตฌ
๋ ผ๋ฌธ์์ ์ธ๊ธํ ํ๊ณ
-
๊ฒ์ ์์กด์ฑ
- ๋น์ ๋ณด์ ๊ฒ์(non-informative search)์ด ์ค๋ฅ์ 23% ์ฐจ์ง
- ๊ฒ์ ์คํจ ์ ์ถ๋ก ๋ณต๊ตฌ ์ด๋ ค์
- ๋ชจ๋ธ์ด ์ถ๋ก ์ ์ฌ๊ตฌ์ฑํ๊ธฐ ์ด๋ ค์
- ๊ตฌ์กฐ์ ๊ฒฝ์ง์ฑ
- Thought -> Action -> Observation์ ๊ณ ์ ๋ ์์
- ์ ์ฐ์ฑ ๋ถ์กฑ
- ํ๋กฌํํ
๊ธฐ๋ฐ์ ํ๊ณ
- Few-shot ์์์ ํ์ง์ ์ฑ๋ฅ ์์กด
- ๋๋ฉ์ธ๋ณ ํ๋กฌํํธ ์ค๊ณ ํ์
- ์ถ๋ก ๋ฃจํ ๋ฌธ์
- ๊ฐ์ Thought๋ Action์ ๋ฐ๋ณตํ๋ ๋ฃจํ์ ๋น ์ง ์ ์์
- ์ธ๊ฐ ์์ค ๋๋น ์ฑ๋ฅ ๊ฒฉ์ฐจ
- WebShop์์ ์ธ๊ฐ ์ ๋ฌธ๊ฐ(50%) ๋๋น ์ฌ์ ํ ๋ฎ์ ์ฑ๋ฅ(40%)
ํฅํ ์ฐ๊ตฌ ๋ฐฉํฅ
| ๋ฐฉํฅ | ์ค๋ช |
|---|---|
| ๊ฐํํ์ต ํตํฉ | RL์ ํตํ ์ฅ๊ธฐ ๊ณํ ๋ฐ ์ ๋ต ํ์ต, ๋ณด์/ํจ๋ํฐ ๊ธฐ๋ฐ ํ๋ ๊ฐ์ |
| ๋ฉํฐํ์คํฌ ํ์ต | ์ฌ๋ฌ ํ์คํฌ ๋์ ํ์ต์ผ๋ก ์ผ๋ฐํ ํฅ์, few-shot ์์กด๋ ๊ฐ์ |
| Fine-tuning | ReAct ๊ถค์ ์ผ๋ก ์ํ ๋ชจ๋ธ ์ง์ ํ์ต, ๋ ๋์ ์ฑ๋ฅ |
| Human Feedback | ์ธ๊ฐ ํผ๋๋ฐฑ ํตํฉ์ผ๋ก ์ถ๋ก ํ์ง ํฅ์ |
| ๋ ๋์ ๊ฒ์ | ์ ๋ณด ๊ฒ์ ํ์ง ๊ฐ์ ์ ํตํ ๋น์ ๋ณด์ ๊ฒ์ ๋ฌธ์ ํด๊ฒฐ |
| ๋ฉํฐ๋ชจ๋ฌ ํ์ฅ | ๋น์ , ์ค๋์ค ๋ฑ ๋ค์ํ ๋ชจ๋ฌ๋ฆฌํฐ ์ง์ |
ํ์ ์ฐ๊ตฌ๋ค์ ๊ฐ์
| ์ฐ๊ตฌ | ALFWorld | WebShop | ๊ฐ์ ์ |
|---|---|---|---|
| ReAct (์๋ณธ) | 71% | 40% | Baseline |
| ReSpAct | 77% (+6%) | 44% (+4%) | Self-Planning ์ถ๊ฐ |
| A3T (ActRe) | 96% (+25%) | 49% (+9%) | ActRe ๊ธฐ๋ฐ ํ์ต |
| REBACT | 98.51% | 61% | Reflection ๊ฐํ |
๐ ๊ด๋ จ ๋ ผ๋ฌธ
์ ํ ์ฐ๊ตฌ
| ๋ ผ๋ฌธ | ๊ด๊ณ | ํต์ฌ ๋ด์ฉ |
|---|---|---|
| Chain-of-Thought Prompting (Wei et al., 2022) | Reasoning ๊ธฐ๋ฐ | ์ถ๋ก ๊ณผ์ ์ ๋จ๊ณ๋ณ๋ก ์์ฑํ์ฌ ๋ณต์กํ ๋ฌธ์ ํด๊ฒฐ |
| Self-Consistency (Wang et al., 2022) | Reasoning ๊ธฐ๋ฐ | ๋ค์ค ์ถ๋ก ๊ฒฝ๋ก ์ํ๋ง ๋ฐ ์ผ๊ด์ฑ ๊ฒ์ฆ |
| Zero-shot CoT (Kojima et al., 2022) | Reasoning ๊ธฐ๋ฐ | “Let’s think step by step”์ผ๋ก ์ ๋ก์ท ์ถ๋ก |
| Inner Monologue (Huang et al., 2022) | Acting ๊ธฐ๋ฐ | ๋ก๋ด ํ๊ฒฝ์์ closed-loop ํผ๋๋ฐฑ ์์คํ |
| SayCan (Ahn et al., 2022) | Acting ๊ธฐ๋ฐ | LLM + ๋ก๋ด ํ๋ ๊ฒฐํฉ |
| WebGPT (Nakano et al., 2021) | Acting ๊ธฐ๋ฐ | ์น ๋ธ๋ผ์ฐ์ง์ ํตํ QA |
ํ์/๊ด๋ จ ์ฐ๊ตฌ
| ๋ ผ๋ฌธ | ๊ด๊ณ | ํต์ฌ ๋ด์ฉ |
|---|---|---|
| Reflexion (Shinn et al., 2023) | ReAct ํ์ฅ | ์๊ธฐ ๋ฐ์ฑ์ ํตํ ์์ด์ ํธ ๊ฐ์ , ๋ฉ๋ชจ๋ฆฌ ํผ๋๋ฐฑ |
| Tree of Thoughts (Yao et al., 2023) | Reasoning ํ์ฅ | ๋ค์ค ์ถ๋ก ๊ฒฝ๋ก ํธ๋ฆฌ ํ์ |
| Toolformer (Schick et al., 2023) | ๋๊ตฌ ์ฌ์ฉ | LLM์ ์๊ฐ ์ง๋ API ํธ์ถ ํ์ต |
| MRKL Systems (Karpas et al., 2022) | ๊ด๋ จ ํ๋ ์์ํฌ | Modular Reasoning, Knowledge, Language |
| AutoGPT, BabyAGI (2023) | ์ค์ฉ ์์ฉ | ReAct ๊ธฐ๋ฐ ์์จ ์์ด์ ํธ |
ReAct vs Inner Monologue ์ฐจ์ด์
- Inner Monologue: Closed-loop ํผ๋๋ฐฑ ์์คํ ์ ์ฒซ ๋ฒ์งธ ์ฐ๊ตฌ, ReAct์ ์๊ฐ
- ReAct ์ ์๋ค์ ์ฃผ์ฅ: Inner Monologue๋ ์ง์ ํ ์๋ฏธ์ “inner thoughts”๋ฅผ ํฌํจํ์ง ์์
- ReAct๋ explicitํ reasoning traces๋ฅผ ํตํด ๋ ๋ช ํํ ์ถ๋ก ๊ณผ์ ์ ๊ณต
๐ป ์ค๋ฌด ์ ์ฉ ํฌ์ธํธ
ReAct ํ๋กฌํํธ ํ ํ๋ฆฟ (QA์ฉ)
Solve a question answering task with interleaving Thought, Action, Observation steps.
Thought can reason about the current situation.
Action can be three types:
(1) Search[entity]: searches the exact entity on Wikipedia and returns the first paragraph.
(2) Lookup[keyword]: returns the next sentence containing keyword in the current passage.
(3) Finish[answer]: returns the answer and finishes the task.
Here are some examples:
{few_shot_examples}
Question: {input_question}
{agent_scratchpad}
LangChain ๊ตฌํ ์์ (Classic)
from langchain import hub
from langchain.agents import AgentExecutor, create_react_agent
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_openai import ChatOpenAI
# 1. ํ๋กฌํํธ ๋ก๋
prompt = hub.pull("hwchase17/react")
# 2. LLM ์ด๊ธฐํ
llm = ChatOpenAI(model="gpt-4", temperature=0)
# 3. ๋๊ตฌ ์ ์
tools = [TavilySearchResults(max_results=3)]
# 4. ReAct ์์ด์ ํธ ์์ฑ
agent = create_react_agent(llm, tools, prompt)
# 5. ์คํ๊ธฐ ์์ฑ
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
verbose=True,
max_iterations=10,
handle_parsing_errors=True
)
# 6. ์คํ
result = agent_executor.invoke({
"input": "What is the elevation range of the area that the eastern sector of Colorado orogeny extends into?"
})
LangGraph ๊ตฌํ (Modern Approach – ๊ถ์ฅ)
from langgraph.prebuilt import create_react_agent
from langchain_core.tools import tool
@tool
def search_wikipedia(query: str) -> str:
"""Search Wikipedia for information about a topic."""
# Wikipedia API ํธ์ถ ๊ตฌํ
return wikipedia_api.search(query)
@tool
def lookup_keyword(keyword: str) -> str:
"""Look up a keyword in the current page."""
return current_page.find(keyword)
# ReAct ์์ด์ ํธ ์์ฑ
graph = create_react_agent(
model="anthropic:claude-3-7-sonnet-latest",
tools=[search_wikipedia, lookup_keyword],
prompt="You are a helpful research assistant."
)
# ์คํ
inputs = {"messages": [{"role": "user", "content": "์ง๋ฌธ ๋ด์ฉ"}]}
for chunk in graph.stream(inputs, stream_mode="updates"):
print(chunk)
์ปค์คํ ReAct ํ๋กฌํํธ ํ ํ๋ฆฟ (ํ๊ตญ์ด)
REACT_PROMPT_KR = """๋ค์ ๋๊ตฌ๋ค์ ์ฌ์ฉํ์ฌ ์ง๋ฌธ์ ๋ตํ์ธ์:
{tools}
๋ค์ ํ์์ ์ฌ์ฉํ์ธ์:
Question: ๋ตํด์ผ ํ ์ง๋ฌธ
Thought: ๋ฌด์์ ํด์ผ ํ ์ง ํญ์ ์๊ฐํ์ธ์
Action: [{tool_names}] ์ค ํ๋์ ์ก์
Action Input: ์ก์
์ ๋ํ ์
๋ ฅ
Observation: ์ก์
์ ๊ฒฐ๊ณผ
... (Thought/Action/Action Input/Observation์ N๋ฒ ๋ฐ๋ณต)
Thought: ์ด์ ์ต์ข
๋ต์ ์์์ต๋๋ค
Final Answer: ์๋ ์ง๋ฌธ์ ๋ํ ์ต์ข
๋ต๋ณ
์์ํ์ธ์!
Question: {input}
{agent_scratchpad}"""
์ค๋ฌด ์ ์ฉ ์ ๊ณ ๋ ค์ฌํญ
| ๊ณ ๋ ค์ฌํญ | ๊ถ์ฅ ์ฌํญ |
|---|---|
| Few-shot ์์ | ๋๋ฉ์ธ์ ๋ง๋ ๊ณ ํ์ง ์์ 3-6๊ฐ ์ค๋น |
| ๋๊ตฌ ์ค๊ณ | ๋ช ํํ ์ค๋ช ๊ณผ ํ๋ผ๋ฏธํฐ ์ ์ ํ์ |
| ์ต๋ ๋ฐ๋ณต ํ์ | ๋ฌดํ ๋ฃจํ ๋ฐฉ์ง๋ฅผ ์ํด max_iterations ์ค์ (7-10 ๊ถ์ฅ) |
| ์๋ฌ ์ฒ๋ฆฌ | ๊ฒ์ ์คํจ ์ ๋์ฒด ์ ๋ต ๊ตฌํ, ํ์ฑ ์๋ฌ ํธ๋ค๋ง |
| ํ ํฐ ๊ด๋ฆฌ | Thought ์์ฑ์ผ๋ก ์ธํ ์ถ๊ฐ ํ ํฐ ๋น์ฉ ๊ณ ๋ ค |
| ๋ก๊น | Thought/Action/Observation ์ ์ฒด ๋ก๊น ์ผ๋ก ๋๋ฒ๊น |
| ํด๋ฐฑ ์ ๋ต | ReAct ์คํจ ์ CoT ํด๋ฐฑ ๊ตฌํ ๊ถ์ฅ |
๋๋ฒ๊น ํ
# verbose=True๋ก ์ค์ ํ์ฌ ์ ์ฒด ์ถ๋ก ๊ณผ์ ํ์ธ
agent_executor = AgentExecutor(
agent=agent,
tools=tools,
verbose=True, # ์ถ๋ก ๊ณผ์ ์ถ๋ ฅ
return_intermediate_steps=True # ์ค๊ฐ ๋จ๊ณ ๋ฐํ
)
result = agent_executor.invoke({"input": "์ง๋ฌธ"})
# ์ค๊ฐ ๋จ๊ณ ๋ถ์
for step in result["intermediate_steps"]:
action, observation = step
print(f"Action: {action.tool}")
print(f"Input: {action.tool_input}")
print(f"Observation: {observation}")
print("---")
๐ท๏ธ Tags
#AIAgent #ReAct #Reasoning #Acting #LLM #PromptEngineering #ChainOfThought #CoT #Hallucination #HotpotQA #FEVER #ALFWorld #WebShop #LangChain #LangGraph #ICLR2023 #Princeton #GoogleBrain #LanguageModel #AgenticAI #ToolUse #ThoughtActionObservation #InteractiveDecisionMaking #FewShotLearning #WikipediaAPI