[AI Paper] ๐ Reflexion: Language Agents with Verbal Reinforcement Learning
๐ Reflexion: Language Agents with Verbal Reinforcement Learning
๐ ๋ฉํ ์ ๋ณด
| ํญ๋ชฉ | ๋ด์ฉ |
|---|---|
| ์ ์ | Noah Shinn, Federico Cassano, Edward Berman, Ashwin Gopinath, Karthik Narasimhan, Shunyu Yao |
| ์์ | Northeastern University (Khoury College), MIT, Princeton University |
| ๋ฐํ์ฒ | NeurIPS 2023 (37th Conference on Neural Information Processing Systems) |
| ์ฐ๋ | 2023 |
| arXiv | 2303.11366 |
| GitHub | noahshinn/reflexion |
| OpenReview | vAElhFcKW6 |
๐ฏ ํ์ค ์์ฝ
LLM ์์ด์ ํธ๊ฐ ๊ฐ์ค์น ์ ๋ฐ์ดํธ ์์ด ์ธ์ด์ ์๊ธฐ ์ฑ์ฐฐ(verbal self-reflection)์ ํตํด ์คํจ ๊ฒฝํ์ผ๋ก๋ถํฐ ํ์ตํ์ฌ ์์ฌ๊ฒฐ์ , ์ถ๋ก , ์ฝ๋ฉ ํ์คํฌ์์ ์ฑ๋ฅ์ ํฌ๊ฒ ํฅ์์ํค๋ ์๋ก์ด ๊ฐํํ์ต ํจ๋ฌ๋ค์์ ์ ์ํ๋ค.
๐ ์ฐ๊ตฌ ๋ฐฐ๊ฒฝ ๋ฐ ๋๊ธฐ
๊ธฐ์กด RL์ ํ๊ณ
- ๋ฐ์ดํฐ ๋นํจ์จ์ฑ
- ์ ํต์ ์ธ ๊ฐํํ์ต(RL)์ ๋ฐฉ๋ํ ์์ ํ์ต ์ํ๊ณผ ๋น์ฉ์ด ๋ง์ด ๋๋ ๋ชจ๋ธ ํ์ธํ๋์ด ํ์
- Policy gradient๋ value-based ๋ฐฉ๋ฒ๋ค์ extensive training๊ณผ expensive model fine-tuning ์๊ตฌ
- ์ค์นผ๋ผ ๋ณด์์ ํ๊ณ
- ๊ธฐ์กด RL์ ์ค์นผ๋ผ ๋๋ ๋ฒกํฐ ํํ์ ๋ณด์ ์ ํธ๋ฅผ ์ฌ์ฉ
- ์ ํํ credit assignment๊ฐ ์ด๋ ค์ – ์ด๋ค ํ๋์ด ์ฑ๊ณต/์คํจ์ ๊ธฐ์ฌํ๋์ง ํ์ ๊ณค๋
- ๊ตฌ์ฒด์ ์ธ ๊ฐ์ ๋ฐฉํฅ ์ ์ ๋ถ๊ฐ๋ฅ
- ํด์ ๋ถ๊ฐ๋ฅ์ฑ
- ์ ์ฑ ๋คํธ์ํฌ๋ ๊ฐ์น ํจ์์ ํ์ต ๊ณผ์ ์ด ๋ธ๋๋ฐ์ค
- ์์ด์ ํธ๊ฐ ์ ํน์ ํ๋์ ์ ํํ๋์ง ํ์ ํ๊ธฐ ์ด๋ ค์
- ์ธ๊ฐ ํ์ต๊ณผ์ ๊ดด๋ฆฌ
- ์ธ๊ฐ์ ์คํจ๋ก๋ถํฐ ์ฑ์ฐฐ(reflection)ํ๊ณ ๋ค์ ์๋์์ ๊ฐ์ ๋ ๊ณํ์ ์ธ์
- ๊ธฐ์กด LLM ์์ด์ ํธ๋ ์ด๋ฌํ ์ํ์ฐฉ์ค๋ฅผ ํตํ ์๊ฐ ํ์ต ๋ฅ๋ ฅ์ด ๋ถ์กฑ
ํต์ฌ ์ฐ๊ตฌ ์ง๋ฌธ
“LLM ์์ด์ ํธ๊ฐ ๊ฐ์ค์น ์ ๋ฐ์ดํธ ์์ด trial-and-error๋ฅผ ํตํด ๋น ๋ฅด๊ณ ํจ์จ์ ์ผ๋ก ํ์ตํ ์ ์์๊น?”
๐ก ํต์ฌ ์์ด๋์ด
1. Verbal Reinforcement Learning (์ธ์ด์ ๊ฐํํ์ต)
๊ธฐ์กด RL์ด ์ค์นผ๋ผ ๋ณด์์ ์ฌ์ฉํ๋ ๊ฒ๊ณผ ๋ฌ๋ฆฌ, Reflexion์ ์ธ์ด์ ํผ๋๋ฐฑ์ ๊ฐํ ์ ํธ๋ก ์ฌ์ฉ:
Traditional RL: state โ action โ scalar reward โ weight update
Reflexion: state โ action โ verbal feedback โ memory update (no weight change)
ํต์ฌ ์ฐจ๋ณ์ :
– ๊ฐ์ค์น ์
๋ฐ์ดํธ ์์: LLM ํ์ธํ๋ ๋ถํ์
– ์ธ์ด์ ํผ๋๋ฐฑ: ์ค์นผ๋ผ ๊ฐ ๋์ ์์ฐ์ด๋ก ๋ ๊ตฌ์ฒด์ ๊ฐ์ ๋ฐฉํฅ ์ ๊ณต
– Semantic Gradient: ์ธ์ด์ ํผ๋๋ฐฑ์ด ์ผ์ข
์ “์๋ฏธ๋ก ์ ๊ทธ๋๋์ธํธ” ์ญํ
2. Self-Reflection ๋ฉ์ปค๋์ฆ
์์ด์ ํธ๊ฐ ์คํจํ ํ ์๊ธฐ ์ฑ์ฐฐ์ ํตํด ๋ฌด์์ด ์๋ชป๋์๋์ง ๋ถ์ํ๊ณ , ์ด๋ฅผ ์์ฐ์ด๋ก ์ ์ฅ:
์คํจํ ํ์คํฌ โ ์๊ธฐ ์ฑ์ฐฐ ์์ฑ โ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ โ ๋ค์ ์๋์์ ํ์ฉ
Self-Reflection์ ์ญํ :
– ์คํจ ์์ธ ๋ถ์ (What went wrong?)
– ๊ตฌ์ฒด์ ์ธ ๊ฐ์ ๋ฐฉํฅ ์ ์ (What to do differently?)
– ๋ค์ ์๋์ ํ์ฉํ ๊ตํ ์์ฑ
์์: ํ๋ก๊ทธ๋๋ฐ ํ์คํฌ์์ ์คํจ ์
“ํจ์๊ฐ ์์ ์ ๋ ฅ์ ์ฒ๋ฆฌํ์ง ๋ชปํด ์คํจํ์ต๋๋ค. ํฅํ ์๋์์๋ ์์ ์ ๋ ฅ์ ๋ํ ์ฒดํฌ ๋ก์ง์ ๋ฐ๋์ ์ถ๊ฐํด์ผ ํฉ๋๋ค.”
3. ์ํผ์๋ ๋ฉ๋ชจ๋ฆฌ (Episodic Memory)
์ฑ์ฐฐ ๊ฒฐ๊ณผ๋ฅผ ์ํผ์๋ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅํ์ฌ ํ์ ์๋์์ ์ฐธ์กฐ:
| ๋ฉ๋ชจ๋ฆฌ ์ ํ | ์ค๋ช | ์ ์ฅ ๋ด์ฉ |
|---|---|---|
| ๋จ๊ธฐ ๋ฉ๋ชจ๋ฆฌ (Short-term) | ํ์ฌ ์ํผ์๋์ trajectory | action-observation ์ํ์ค |
| ์ฅ๊ธฐ ๋ฉ๋ชจ๋ฆฌ (Long-term) | ๊ณผ๊ฑฐ ์๋๋ค์ self-reflection ๊ฒฐ๊ณผ | ์คํจ ์์ธ ๋ถ์, ๊ฐ์ ๋ฐฉํฅ, ๊ตํ |
์ฅ๊ธฐ ๋ฉ๋ชจ๋ฆฌ์ ์ฅ์ :
– ๋ช
์์ ์ด๊ณ ํด์ ๊ฐ๋ฅํ ๊ฒฝํ ์ ์ฅ
– ๊ตฌ์ฒด์ ์ธ ํ๋ ํํธ ์ ๊ณต
– ๋ค์ ์ํผ์๋์์ ์ฆ์ ํ์ฉ ๊ฐ๋ฅ
4. ํผ๋๋ฐฑ ์ ์ฐ์ฑ
๋ค์ํ ํํ์ ์์ค์ ํผ๋๋ฐฑ ์ ํธ ์์ฉ ๊ฐ๋ฅ:
| ํผ๋๋ฐฑ ์ ํ | ์์ |
|---|---|
| ์ค์นผ๋ผ ๊ฐ | ์ฑ๊ณต/์คํจ, ์ ์, ๋ณด์ |
| ์์ ํ์ ์ธ์ด | ๊ตฌ์ฒด์ ์ธ ์ค๋ฅ ๋ฉ์์ง, ํ๊ฐ ์ฝ๋ฉํธ |
| ์ธ๋ถ ํผ๋๋ฐฑ | ์ปดํ์ผ๋ฌ ์๋ฌ, ํ ์คํธ ๊ฒฐ๊ณผ, ํ๊ฒฝ ํผ๋๋ฐฑ |
| ๋ด๋ถ ์๋ฎฌ๋ ์ด์ | Self-generated tests, ์์ฒด ํ๊ฐ |
๐๏ธ ์ํคํ ์ฒ / ๋ฐฉ๋ฒ๋ก
์์คํ ๊ตฌ์ฑ ์์
Reflexion์ ์ธ ๊ฐ์ง ํต์ฌ ์ปดํฌ๋ํธ๋ก ๊ตฌ์ฑ:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Reflexion Framework โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโ action โโโโโโโโโโโโโโโ โ
โ โ Actor โ โโโโโโโโโโโถ โ Environment โ โ
โ โ (LLM) โ โโโโโโโโโโโ โ โ โ
โ โโโโโโฌโโโโโ observation โโโโโโโโฌโโโโโโโ โ
โ โ โ โ
โ โ trajectory โ reward โ
โ โผ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Evaluator โ โ
โ โ (reward score ๊ณ์ฐ) โ โ
โ โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโ โ
โ โ feedback โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Self-Reflection โ โ
โ โ (์ธ์ด์ ํผ๋๋ฐฑ ์์ฑ) โ โ
โ โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโ โ
โ โ reflection โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Long-term Memory โ โ
โ โ (์ฑ์ฐฐ ๋ด์ฉ ์ ์ฅ) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
1. Actor (ํ๋์)
- ์ญํ : ์ํ ๊ด์ฐฐ์ ๊ธฐ๋ฐ์ผ๋ก ํ ์คํธ์ ํ๋ ์์ฑ
- ๊ตฌํ: Chain-of-Thought (CoT) ๋๋ ReAct ๊ธฐ๋ฐ
- ์ ๋ ฅ: ํ๊ฒฝ ์ํ(observation) + ์ฅ๊ธฐ ๋ฉ๋ชจ๋ฆฌ(reflections)
- ์ถ๋ ฅ: ํ๋(action) ๋ฐ trajectory
- ํน์ง: ๋ฉ๋ชจ๋ฆฌ ์ปดํฌ๋ํธ์ ๊ฒฐํฉํ์ฌ ๊ณผ๊ฑฐ ๊ฒฝํ ํ์ฉ
2. Evaluator (ํ๊ฐ์)
- ์ญํ : Actor๊ฐ ์์ฑํ ์ถ๋ ฅ์ ํ์ง ์ ์ ๊ณ์ฐ
- ์ ๋ ฅ: ์์ฑ๋ trajectory (๋จ๊ธฐ ๋ฉ๋ชจ๋ฆฌ)
- ์ถ๋ ฅ: ๋ณด์ ์ ์ (reward score)
- ๊ตฌํ ๋ฐฉ์:
- Decision-making: ์ฌ์ ์ ์๋ ํด๋ฆฌ์คํฑ ํจ์ ๋๋ GPT ๊ธฐ๋ฐ ์ด์ง ๋ถ๋ฅ
- Reasoning: Exact Match (EM) ๊ธฐ๋ฐ ํ๊ฐ
- Programming: ํ ์คํธ ์คํ ๊ฒฐ๊ณผ (pass/fail)
- ์ฐธ๊ณ : ๋ฐ๋์ LLM์ผ ํ์ ์์ – ๋จ์ ํ ์ด๋ธ ๋ฃฉ์ ๋ ๊ฐ๋ฅ
3. Self-Reflection (์๊ธฐ ์ฑ์ฐฐ)
- ์ญํ : Actor์ ์๊ธฐ ๊ฐ์ ์ ๋๋ ์ธ์ด์ ๊ฐํ ์ ํธ(verbal reinforcement cues) ์์ฑ
- ์
๋ ฅ:
- ๋ณด์ ์ ํธ (reward signal)
- ํ์ฌ trajectory
- ์ฅ๊ธฐ ๋ฉ๋ชจ๋ฆฌ (persistent memory)
- ์ถ๋ ฅ: ๊ตฌ์ฒด์ ์ด๊ณ ๊ด๋ จ์ฑ ์๋ ํผ๋๋ฐฑ (self-reflection)
- ๊ตฌํ: LLM์ ํตํด ๊ตฌํ
- ํต์ฌ ๊ธฐ๋ฅ: ํ๊ฒฝ์ผ๋ก๋ถํฐ์ ํผ๋๋ฐฑ์ ์ธ์ด์ ํํ๋ก ๋ณํํ์ฌ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ
ํ์ต ๋ฃจํ (Learning Loop)
Trial 1: Task ์๋ โ ์คํจ โ ์ฑ์ฐฐ ์์ฑ โ ๋ฉ๋ชจ๋ฆฌ ์ ์ฅ
โ
Trial 2: ๋ฉ๋ชจ๋ฆฌ ์ฐธ์กฐ โ Task ์ฌ์๋ โ ์คํจ โ ์ฑ์ฐฐ ์ถ๊ฐ
โ
Trial 3: ์ถ์ ๋ ๋ฉ๋ชจ๋ฆฌ ์ฐธ์กฐ โ Task ์ฌ์๋ โ ์ฑ๊ณต!
์๊ณ ๋ฆฌ์ฆ ํต์ฌ ๋จ๊ณ:
1. Define: ํ์คํฌ ์ ์
2. Generate: Actor๊ฐ trajectory ์์ฑ
3. Evaluate: Evaluator๊ฐ ๊ฒฐ๊ณผ ํ๊ฐ
4. Reflect: ์คํจ ์ Self-Reflection ์ํ
5. Update: ์ฑ์ฐฐ ๋ด์ฉ์ ์ฅ๊ธฐ ๋ฉ๋ชจ๋ฆฌ์ ์ ์ฅ
6. Iterate: ๋ค์ trajectory ์์ฑ (๋ฉ๋ชจ๋ฆฌ ์ฐธ์กฐ)
ํ์คํฌ๋ณ ๊ตฌํ ์ธ๋ถ์ฌํญ
Decision-Making (AlfWorld)
# ReAct + Reflexion for AlfWorld
def reflexion_decision_making(task, env, max_trials=12):
memory = []
for trial in range(max_trials):
# Actor: ReAct-style reasoning and acting
trajectory = react_agent.run(task, env, memory)
# Evaluator: Heuristic or GPT-based binary classification
success, feedback = evaluate_trajectory(trajectory)
if success:
return trajectory
# Self-Reflection: Generate verbal feedback
reflection = generate_reflection(
trajectory=trajectory,
feedback=feedback,
memory=memory
)
memory.append(reflection)
env.reset()
return None
AlfWorld์์ ์ฅ๊ธฐ ๋ฉ๋ชจ๋ฆฌ๊ฐ ๋์์ด ๋๋ ๋ ๊ฐ์ง ๊ฒฝ์ฐ:
1. ๊ธด trajectory ์ด๋ฐ์ ์ค์๋ฅผ ์๋ณํ๊ณ ์๋ก์ด ํ๋ ์ ํ์ด๋ ์ฅ๊ธฐ ๊ณํ์ ์ ์
2. ๊ฒ์ํด์ผ ํ ํ๋ฉด/์ปจํ
์ด๋๊ฐ ๋๋ฌด ๋ง์ ๋, ์ฌ๋ฌ ์๋์ ๊ฑธ์ณ ๋ฐฉ์ ์ฒด๊ณ์ ์ผ๋ก ํ์
Programming (HumanEval)
# Reflexion for Code Generation
def reflexion_code_generation(problem, tests, max_trials=10):
memory = []
for trial in range(max_trials):
# Actor: Generate code with memory context
code = generate_code(problem, memory)
# Self-Generated Tests (internal feedback)
internal_tests = generate_tests(problem, code)
# Evaluator: Run tests
test_results = run_tests(code, tests + internal_tests)
if all_tests_pass(test_results):
return code
# Self-Reflection
reflection = reflect_on_code(
code=code,
test_results=test_results,
memory=memory
)
memory.append(reflection)
return best_code
Reasoning (HotPotQA)
# Reflexion for Multi-hop QA
def reflexion_reasoning(question, context, max_trials=5):
memory = []
for trial in range(max_trials):
# Actor: CoT reasoning with memory
answer, reasoning_chain = cot_reason(
question, context, memory
)
# Evaluator: Check answer correctness
is_correct, ground_truth = evaluate_answer(answer)
if is_correct:
return answer
# Self-Reflection
reflection = reflect_on_reasoning(
question=question,
reasoning=reasoning_chain,
answer=answer,
memory=memory
)
memory.append(reflection)
return best_answer
๐ ์คํ ๋ฐ ๊ฒฐ๊ณผ
์คํ ํ๊ฒฝ
| ํ์คํฌ ์ ํ | ๋ฒค์น๋งํฌ | ์ค๋ช |
|---|---|---|
| Sequential Decision-Making | AlfWorld | 134๊ฐ ํ ์คํธ ๊ธฐ๋ฐ ํ๊ฒฝ, 6๊ฐ์ง ํ์คํฌ ์ ํ |
| Reasoning | HotPotQA | 100๊ฐ ๋ค์ค ํ ์ถ๋ก ์ง๋ฌธ (distractor ์ค์ ) |
| Programming | HumanEval | 164๊ฐ Python ํ๋ก๊ทธ๋๋ฐ ๋ฌธ์ |
| Programming | LeetcodeHardGym | 40๊ฐ Hard ๋ ๋ฒจ ๋ฌธ์ , 19๊ฐ ์ธ์ด (์๋ก ์ ์) |
์ฃผ์ ๊ฒฐ๊ณผ
1. AlfWorld (Decision-Making)
| ๋ฐฉ๋ฒ | ์ฑ๊ณต๋ฅ |
|---|---|
| ReAct (baseline) | 73% |
| ReAct + Reflexion (Heuristic) | 97% (130/134) |
| ReAct + Reflexion (GPT) | 97% (130/134) |
- ์ ๋์ ์ฑ๋ฅ ํฅ์: +22% (12 iterative steps ๋ด)
- 134๊ฐ ํ์คํฌ ์ค ๋จ 4๊ฐ๋ง ์คํจ
2. HotPotQA (Reasoning)
| ๋ฐฉ๋ฒ | ์ ํ๋ |
|---|---|
| GPT-4 (baseline) | 34% |
| CoT + Episodic Memory | 36% |
| GPT-4 + Reflexion | 54% |
- ์ ๋์ ์ฑ๋ฅ ํฅ์: +20%
- ๊ฒ์, ์ ๋ณด ์ถ์ถ, ์ถ๋ก ๋ฅ๋ ฅ ๋ชจ๋ ํฅ์
3. HumanEval (Code Generation)
| ๋ฐฉ๋ฒ | Pass@1 |
|---|---|
| GPT-4 (baseline) | 67.0% |
| CodeT (previous SOTA) | 65.8% |
| GPT-4 + Reflexion | 91.0% |
- ์ ๋์ ์ฑ๋ฅ ํฅ์: +24% (GPT-4 ๋๋น)
- ๋น์ SOTA ๋ฌ์ฑ (์ด์ ๊ธฐ๋ก์ธ GPT-4์ 80% ์ด๊ณผ)
ํ์ต ๊ณก์ ๋ถ์
Performance vs Trial Number (AlfWorld)
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Trial 1: โโโโโโโโโโโโโโโโโโโโ 60%
Trial 3: โโโโโโโโโโโโโโโโโโโโ 90%
Trial 6: โโโโโโโโโโโโโโโโโโโโ 95%
Trial 12: โโโโโโโโโโโโโโโโโโโโ 97%
ReAct (no reflection): plateaus at ~75%
Reflexion: continues to improve with more trials
ํต์ฌ ๋ฐ๊ฒฌ: ReAct๋ ์ผ์ ์์ค์์ ์ฑ๋ฅ์ด ์ ์ฒด๋์ง๋ง, Reflexion์ ์๋ ํ์๊ฐ ์ฆ๊ฐํจ์ ๋ฐ๋ผ ์ง์์ ์ผ๋ก ์ฑ๋ฅ์ด ํฅ์๋จ
Ablation Study ๊ฒฐ๊ณผ
Self-Reflection์ ํจ๊ณผ
- ์ํผ์๋ ๋ฉ๋ชจ๋ฆฌ ํ์ต ๋๋น 8% ์ ๋์ ์ฑ๋ฅ ํฅ์
- refinement-only ์ ๊ทผ๋ฒ๋ณด๋ค self-reflection ๊ธฐ๋ฐ refinement๊ฐ ๋ ํจ๊ณผ์ ์์ ์ ์ฆ
์ปดํฌ๋ํธ๋ณ ๊ธฐ์ฌ๋ (HumanEval)
| ๊ตฌ์ฑ ์์ | Pass@1 |
|---|---|
| Base (no reflection) | 67.0% |
| + Self-generated tests only | 77.0% |
| + Self-reflection only | 80.0% |
| + Both (full Reflexion) | 91.0% |
- Self-generated tests์ self-reflection ๋ชจ๋ ์ค์
- ๋ ์์์ ์๋์ง ํจ๊ณผ ํ์ธ
๐ช ๊ฐ์ ๋ฐ ๊ธฐ์ฌ
๊ธฐ์ ์ ๊ฐ์
- ๊ฒฝ๋์ฑ (Lightweight)
- ๊ฐ์ค์น ์ ๋ฐ์ดํธ ๋ถํ์: Fine-tuning ์์ด in-context learning๋ง์ผ๋ก ์ฑ๋ฅ ํฅ์
- ๊ณ์ฐ ํจ์จ์ฑ: ์ถ๊ฐ ํ์ต ๋น์ฉ ์ต์ํ
- ๋น ๋ฅธ ์ ์: ๋ช ๋ฒ์ ์๋๋ง์ผ๋ก ๊ฐ์
- ํด์ ๊ฐ๋ฅ์ฑ (Interpretability)
- ์ธ์ด์ ํผ๋๋ฐฑ: ์ ์คํจํ๋์ง ์์ฐ์ด๋ก ์ค๋ช
- ํฌ๋ช ํ ํ์ต ๊ณผ์ : ์ฑ์ฐฐ ๋ด์ฉ์ ์ง์ ํ์ธ ๊ฐ๋ฅ
- ๋๋ฒ๊น ์ฉ์ด: ์์ด์ ํธ์ ์ฌ๊ณ ๊ณผ์ ์ถ์
- ์ ์ฐ์ฑ (Flexibility)
- ๋ค์ํ ํผ๋๋ฐฑ ์์ค: ์ธ๋ถ/๋ด๋ถ, ์ค์นผ๋ผ/์ธ์ด
- ํ์คํฌ ๋ฒ์ฉ์ฑ: ์์ฌ๊ฒฐ์ , ์ฝ๋ฉ, ์ถ๋ก ๋ชจ๋ ์ ์ฉ
- ๊ธฐ์กด ๊ธฐ๋ฒ๊ณผ ๊ฒฐํฉ: CoT, ReAct์ ์ฝ๊ฒ ํตํฉ
- ๊ธฐ์กด ๋ฐฉ๋ฒ ๋๋น ์ฅ์
- ์ ํต์ RL๋ณด๋ค ์ธ๋ฐํ ํผ๋๋ฐฑ ๊ฐ๋ฅ (ํ๊ฒํ ๋ ํ๋ ๋ณ๊ฒฝ)
- ๋ช ์์ ์ด๊ณ ํด์ ๊ฐ๋ฅํ ์ํผ์๋ ๋ฉ๋ชจ๋ฆฌ
- ๋ค์ ์ํผ์๋์์ ๋ช ํํ ํ๋ ํํธ ์ ๊ณต
ํ์ ์ ๊ธฐ์ฌ
- ์๋ก์ด ํจ๋ฌ๋ค์ ์ ์: “Verbal RL” – ์ ์ฑ
์
(๋ฉ๋ชจ๋ฆฌ ์ธ์ฝ๋ฉ, LLM ํ๋ผ๋ฏธํฐ)๋ก ํ๋ผ๋ฏธํฐํ - SOTA ๋ฌ์ฑ: HumanEval์์ ๋น์ ์ต๊ณ ์ฑ๋ฅ ๊ธฐ๋ก
- ๋ฒค์น๋งํฌ ๊ณต๊ฐ: LeetcodeHardGym ํ๊ฒฝ ๊ณต๊ฐ (40๊ฐ hard-level ๋ฌธ์ , 19๊ฐ ์ธ์ด)
- ์คํ์์ค: ์ฝ๋, ๋ฐ๋ชจ, ๋ฐ์ดํฐ์ ๋ชจ๋ ๊ณต๊ฐ
โ ๏ธ ํ๊ณ์ ๋ฐ ํฅํ ์ฐ๊ตฌ
๋ ผ๋ฌธ์์ ์ธ๊ธํ ํ๊ณ
1. Local Minima ๋ฌธ์
- Reflexion์ ๋ณธ์ง์ ์ผ๋ก ์์ฐ์ด๋ฅผ ์ฌ์ฉํ ์ ์ฑ ์ต์ ํ ๊ธฐ๋ฒ
- ์ ์ฑ ์ต์ ํ๋ ๊ฐ๋ ฅํ์ง๋ง ๋น์ต์ ๊ตญ์ ์ต์๊ฐ(non-optimal local minima)์ ๋น ์ง ์ ์์
2. ๋ฉ๋ชจ๋ฆฌ ์ฉ๋ ์ ํ
- ์ฌ๋ผ์ด๋ฉ ์๋์ฐ ๋ฐฉ์์ผ๋ก ์ฅ๊ธฐ ๋ฉ๋ชจ๋ฆฌ ์ฉ๋ ์ ํ
- LLM ์ปจํ ์คํธ ๊ธธ์ด ์ ์ฝ์ผ๋ก ์ธํ ์ ๋ณด ์์ค ๊ฐ๋ฅ
- ์ ์๋ค์ ํฅํ ์ฐ๊ตฌ์์ ๋ฒกํฐ ์๋ฒ ๋ฉ DB๋ SQL DB๋ก ํ์ฅ ๊ถ์ฅ
3. Self-Evaluation ์์กด์ฑ
- LLM์ ์๊ธฐ ํ๊ฐ ๋ฅ๋ ฅ์ ํฌ๊ฒ ์์กด
- ํ๊ฐ ๋ชจ๋ธ์ด ๋ถ์ ํํ๋ฉด ์๋ชป๋ ๋ฐฉํฅ์ผ๋ก ํ์ต
- ์ ํต์ RL๊ณผ ๋ฌ๋ฆฌ ์ฑ๊ณต์ ๋ํ ํ์์ ๋ณด์ฅ ์์
4. Self-Reflection ํ์ง ๋ณ๋
- LLM์ด ์์ฑํ๋ ํผ๋๋ฐฑ์ ์ ํ์ฑ๊ณผ ์คํ ๊ฐ๋ฅ์ฑ์ด ํญ์ ๋ณด์ฅ๋์ง ์์
- ํต์ฌ ์ด์๋ฅผ ๋์น๊ฑฐ๋ ์ถฉ๋ถํ ์ ํํ์ง ์์ ํผ๋๋ฐฑ ์์ฑ ์ํ
5. ์ฝ๋ ์์ฑ ํนํ ํ๊ณ
- ๋น๊ฒฐ์ ์ ํจ์: ์ถ๋ ฅ์ด ๋งค๋ฒ ๋ฌ๋ผ์ง๋ ํจ์ ํ๊ฐ ์ด๋ ค์
- ํ๋์จ์ด ์์กด์ ํจ์: ํ๊ฒฝ์ ๋ฐ๋ผ ์ถ๋ ฅ์ด ๋ฌ๋ผ์ง๋ ๊ฒฝ์ฐ
- Test-driven development์ ์ ํํ ์ ์ถ๋ ฅ ๋งคํ ํ๊ณ
ํฅํ ์ฐ๊ตฌ ๋ฐฉํฅ
- ๊ณ ๊ธ ๋ฉ๋ชจ๋ฆฌ ๊ตฌ์กฐ: ๋ฒกํฐ ์๋ฒ ๋ฉ ๋ฐ์ดํฐ๋ฒ ์ด์ค, SQL DB, ๊ตฌ์กฐํ๋ ์ง์ ๊ทธ๋ํ
- Meta-Policy Reflexion: ํ์คํฌ ํนํ ์ฑ์ฐฐ์ ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ๊ท์น์ผ๋ก ํตํฉ
- LLM ๋ฅ๋ ฅ ํฅ์ ํ์ฉ: ๋ชจ๋ธ ๋ฐ์ ์ ๋ฐ๋ฅธ Reflexion ํจ๊ณผ ์ฆ๋ ๊ธฐ๋
- ํ์ด๋ธ๋ฆฌ๋ ํ์ต: ์ ํต์ RL๊ณผ์ ๊ฒฐํฉ์ ํตํ ์๋์ง
๐ ๊ด๋ จ ๋ ผ๋ฌธ
์ ํ ์ฐ๊ตฌ
| ๋ ผ๋ฌธ | ์ฐ๋ | ๊ด๊ณ |
|---|---|---|
| ReAct: Synergizing Reasoning and Acting | 2022 | Actor ๋ชจ๋ธ์ ๊ธฐ๋ฐ, ์ถ๋ก ๊ณผ ํ๋ ์ธํฐ๋ฆฌ๋น |
| Chain-of-Thought Prompting | 2022 | ๋จ๊ณ๋ณ ์ถ๋ก ๊ธฐ๋ฒ, Actor ๋ชจ๋ธ๋ก ์ฌ์ฉ |
| Self-Consistency | 2022 | ๋ค์ํ ์ถ๋ก ๊ฒฝ๋ก ์ํ๋ง ํ ์ผ๊ด๋ ๋ต๋ณ ์ ํ |
| Self-Refine | 2023 | ์ ์ฌํ ๋ฐ๋ณต์ ์๊ธฐ ๊ฐ์ ์ ๊ทผ |
ํ์/๋ฐ์ ์ฐ๊ตฌ
| ๋ ผ๋ฌธ | ๊ด๊ณ |
|---|---|
| LATS (Language Agent Tree Search) | Reflexion + Monte-Carlo Tree Search ๊ฒฐํฉ |
| Tree of Thoughts | ๋ค์ค ์ถ๋ก ๊ฒฝ๋ก๋ฅผ ๋์์ ๊ณ ๋ ค |
| Meta-Policy Reflexion (MPR) | ์ฌ์ฌ์ฉ ๊ฐ๋ฅํ ๊ท์น์ผ๋ก ์ฑ์ฐฐ ํตํฉ |
| MAR (Multi-Agent Reflexion) | ๋ค์ค ์์ด์ ํธ ํ๊ฒฝ์ผ๋ก ํ์ฅ |
๊ด๋ จ ํ๋ ์์ํฌ
- LangChain/LangGraph: Reflexion ํจํด ๊ตฌํ ์ง์ (ํํ ๋ฆฌ์ผ ์ ๊ณต)
- AutoGen: ๋ฉํฐ ์์ด์ ํธ reflexion ๊ตฌํ
- Swarms: ReflexionAgent ํด๋์ค ์ ๊ณต
๐ป ์ค๋ฌด ์ ์ฉ ํฌ์ธํธ
Self-Reflection ํ๋กฌํํธ ์์
์ผ๋ฐ์ ์ธ ์๊ธฐ ์ฑ์ฐฐ ํ๋กฌํํธ
You are an advanced reasoning agent that can improve based on
self-reflection. You will be given a previous reasoning trial
in which you were given access to relevant context and a
question to answer. You were unsuccessful in answering the
question either because you guessed the wrong answer with a
probability above the given threshold, or you used up your
set number of reasoning steps.
In a few sentences, diagnose a possible reason for failure and
devise a new, concise, high-level plan that aims to mitigate
the same failure. Use complete sentences.
Previous Trial:
{previous_trial}
Reflection:
์์ธ ์๊ธฐ ์ฑ์ฐฐ ํ๋กฌํํธ (์ค๋ฌด์ฉ)
You are an expert in {topic}. You have incorrectly answered the
following multiple-choice question. Your task is to reflect on
the problem, your solution, and the correct answer.
**Question**: {question}
**Your Answer**: {agent_answer}
**Correct Answer**: {correct_answer}
Please provide:
1. **Why you failed**: Explain why your answer was incorrect
2. **Error keywords**: List keywords describing your error (general โ specific)
3. **Corrected solution**: Solve the problem step-by-step based on the correct answer
4. **Future instructions**: Create detailed instructions to avoid this error
5. **General advice**: List advice for similar problems
Be concise but capture all essential information.
์ฝ๋ ์์ฑ์ฉ ์๊ธฐ ์ฑ์ฐฐ ํ๋กฌํํธ
You are a Python programming assistant. Your previous code failed the test cases.
**Task**: {task_description}
**Your Code**:
```python
{failed_code}
</code></pre>
<strong>Error Message</strong>: {error_message}
<strong>Failed Test Cases</strong>: {failed_tests}
Reflect on your mistake and provide:
1. Root cause of the failure
2. What edge cases you missed
3. Specific changes needed to fix the code
4. Lessons for future similar tasks
<pre><code><br />### ๊ตฌํ ํจํด (LangGraph)
```python
from langgraph.graph import StateGraph, END
from langchain_anthropic import ChatAnthropic
from typing import TypedDict, List
# State definition
class ReflexionState(TypedDict):
task: str
trajectory: List[str]
reflections: List[str]
trial: int
max_trials: int
success: bool
# Nodes
def actor_node(state: ReflexionState) -> ReflexionState:
"""Generate trajectory using LLM with memory context"""
llm = ChatAnthropic(model="claude-sonnet-4-20250514")
prompt = f"""
Task: {state['task']}
Previous reflections: {state['reflections']}
Generate a solution:
"""
response = llm.invoke(prompt)
state['trajectory'].append(response.content)
return state
def evaluator_node(state: ReflexionState) -> ReflexionState:
"""Evaluate the trajectory"""
state['success'] = evaluate(state['trajectory'][-1])
return state
def reflection_node(state: ReflexionState) -> ReflexionState:
"""Generate self-reflection"""
llm = ChatAnthropic(model="claude-sonnet-4-20250514")
prompt = f"""
Failed attempt: {state['trajectory'][-1]}
What went wrong and how to improve?
"""
reflection = llm.invoke(prompt).content
state['reflections'].append(reflection)
state['trial'] += 1
return state
def should_continue(state: ReflexionState) -> str:
if state['success']:
return END
if state['trial'] >= state['max_trials']:
return END
return "reflect"
# Build graph
workflow = StateGraph(ReflexionState)
workflow.add_node("actor", actor_node)
workflow.add_node("evaluator", evaluator_node)
workflow.add_node("reflect", reflection_node)
workflow.set_entry_point("actor")
workflow.add_edge("actor", "evaluator")
workflow.add_conditional_edges(
"evaluator",
should_continue,
{"reflect": "reflect", END: END}
)
workflow.add_edge("reflect", "actor")
app = workflow.compile()
์ค๋ฌด ์ ์ฉ ํ
1. ์ ์ ํ ์๋ ํ์ ์ค์
- ์ฝ๋ฉ ํ์คํฌ: 5-10ํ
- ์์ฌ๊ฒฐ์ : 10-15ํ
- ์ถ๋ก : 3-5ํ
2. ํผ๋๋ฐฑ ํ์ง ํ๋ณด
- ๊ฐ๋ฅํ๋ฉด ๊ตฌ์ฒด์ ์ธ ์ธ๋ถ ํผ๋๋ฐฑ ํ์ฉ (ํ ์คํธ ์๋ฌ ๋ฉ์์ง ๋ฑ)
- LLM ํ๊ฐ ์ ๋ช ํํ ํ๊ฐ ๊ธฐ์ค ์ ๊ณต
3. ๋น์ฉ ์ต์ ํ
- Self-reflection์ ์์ ๋ชจ๋ธ ์ฌ์ฉ ๊ณ ๋ ค
- ๋ถํ์ํ ์๋ ์ค์ด๊ธฐ ์ํ early stopping ๊ตฌํ
4. ์ ์ฉ ์ ํฉ์ฑ ํ๋จ
- ์ ํฉ: ๋ณต์กํ ํ์คํฌ, trial-and-error ๊ฐ๋ฅ, ๋ช ํํ ํผ๋๋ฐฑ ์ ํธ ์กด์ฌ
- ๋ถ์ ํฉ: ๋จ์ ํ์คํฌ, ๋จ์ผ ์๋๋ก ์ถฉ๋ถ, ํผ๋๋ฐฑ ๋ชจํธ
๐ท๏ธ Tags
#AIAgent #SelfReflection #VerbalRL #ReinforcementLearning #LLM #NeurIPS2023 #CodeGeneration #ReAct #ChainOfThought #EpisodicMemory #LanguageAgent #SelfImprovement #HumanEval #AlfWorld #HotPotQA #PromptEngineering #AgenticAI #TrialAndError