Files
2nd/10_Wiki/Topic_Programming/AI_and_ML/Iterative Prompting.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

8.1 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-iterative-prompting Iterative Prompting 10_Wiki/Topics verified self
iterative prompting
refinement
self-refine
chain-of-verification
agent loop
none A 0.92 applied
llm
prompt-engineering
iterative
self-refine
cove
agent
2026-05-10 pending
language framework
Python LangChain / OpenAI / Anthropic

Iterative Prompting

매 한 줄

"매 single prompt 의 X — 매 의 의 의 multiple round 의 의 의 quality ↑". 매 self-refine, CoVe (Chain-of-Verification), self-consistency, debate, agent loop. 매 modern: 매 reasoning model (o1, R1) 의 의 의 의 internal iteration. 매 trade-off: cost ↑, latency ↑.

매 핵심

매 patterns

  • Self-Refine (Madaan 2023): 매 generate → critique → refine.
  • CoVe (Dhuliawala 2023): 매 plan verification → check → refine.
  • Self-Consistency (Wang 2022): 매 multiple sample → majority.
  • Debate (Du 2023): 매 multi-LLM argue.
  • ReAct (Yao 2022): 매 reason + act loop.
  • Reflexion (Shinn 2023): 매 RL-style with verbal feedback.

매 응용

  1. Math reasoning.
  2. Code generation.
  3. Long writing.
  4. Fact verification.
  5. Agent task.

💻 패턴

Self-refine (Madaan)

def self_refine(prompt, llm, max_iter=3):
    output = llm.generate(prompt)
    for _ in range(max_iter):
        critique = llm.generate(f"""Critique this output:
{output}
List specific issues. If perfect, say 'DONE'.""")
        if 'DONE' in critique: return output
        output = llm.generate(f"""Original: {prompt}
Previous output: {output}
Critique: {critique}
Improved output:""")
    return output

Chain-of-Verification (CoVe)

def cove(question, llm):
    # 매 1. Initial answer
    initial = llm.generate(f'Answer: {question}')
    
    # 매 2. Plan verification questions
    verify_qs = llm.generate(f"""Generate verification questions for:
{initial}
List as numbered questions.""").split('\n')
    
    # 매 3. Answer each independently (avoid bias)
    verifications = [llm.generate(f'Answer: {q}') for q in verify_qs if q.strip()]
    
    # 매 4. Refine
    return llm.generate(f"""Original: {initial}
Verifications: {verifications}
Refined answer accounting for any inconsistencies:""")

Self-consistency

def self_consistency(question, llm, n=10):
    """매 sample N times, majority vote."""
    answers = [llm.generate(question, temperature=0.7) for _ in range(n)]
    extracted = [extract_answer(a) for a in answers]
    from collections import Counter
    return Counter(extracted).most_common(1)[0][0]

Multi-agent debate

def debate(question, agents, n_rounds=3):
    answers = {a.name: a.generate(question) for a in agents}
    for r in range(n_rounds):
        for a in agents:
            others = '\n'.join(f'{n}: {ans}' for n, ans in answers.items() if n != a.name)
            answers[a.name] = a.generate(f"""Question: {question}
Other agents:
{others}
Refine your answer (or stick if confident):""")
    return answers

ReAct (reason + act)

def react(task, llm, tools):
    history = [f'Task: {task}']
    for _ in range(10):
        thought = llm.generate('\n'.join(history) + '\nThought:')
        history.append(f'Thought: {thought}')
        
        if 'final answer' in thought.lower():
            return thought
        
        action = llm.generate('\n'.join(history) + '\nAction:')
        observation = execute(action, tools)
        history.append(f'Action: {action}\nObservation: {observation}')

Reflexion (verbal RL)

def reflexion(task, llm, tools, max_attempts=5):
    memory = []
    for attempt in range(max_attempts):
        result = react_with_memory(task, llm, tools, memory)
        success = evaluate(result)
        if success: return result
        
        # 매 reflect
        reflection = llm.generate(f"""Task: {task}
Attempt {attempt}: {result}
What went wrong? What should I try differently?""")
        memory.append(reflection)
    return result

Iterative refinement (writing)

def iterative_writing(topic, llm, draft_iterations=3):
    draft = llm.generate(f'Outline: {topic}')
    
    for _ in range(draft_iterations):
        feedback = llm.generate(f"""Critique:
- Clarity (1-10)
- Argument strength (1-10)
- Specific issues
{draft}""")
        draft = llm.generate(f"""Revise based on feedback:
{feedback}
Original:
{draft}""")
    return draft

Self-correction (math)

def self_correct_math(problem, llm):
    answer = llm.generate(f'Solve step by step: {problem}')
    
    # 매 verify
    check = llm.generate(f"""Check this solution:
{answer}
Verify each step. If error, point it out.""")
    
    if 'error' in check.lower():
        answer = llm.generate(f"""Original: {answer}
Check: {check}
Corrected solution:""")
    
    return answer

Best-of-N + judge

def best_of_n(prompt, llm, judge_llm, n=8):
    candidates = [llm.generate(prompt, temperature=0.7) for _ in range(n)]
    judge_prompt = f"""Pick best answer.

Candidates:
{format_candidates(candidates)}

Output just the index."""
    best_idx = int(judge_llm.generate(judge_prompt))
    return candidates[best_idx]

Tree-of-Thoughts (ToT)

def tree_of_thoughts(problem, llm, branching=3, depth=4):
    """매 매 step 의 의 의 multiple thoughts → 매 best."""
    paths = [[]]
    for _ in range(depth):
        new_paths = []
        for path in paths:
            thoughts = [llm.generate(f'{problem}\nPath: {path}\nNext thought:') for _ in range(branching)]
            for t in thoughts:
                new_paths.append(path + [t])
        # 매 score + prune
        scored = [(score(p, problem, llm), p) for p in new_paths]
        paths = [p for _, p in sorted(scored, key=lambda x: -x[0])[:branching]]
    return paths[0]

Cost monitoring

def cost_aware_iterate(prompt, llm, budget_tokens):
    used = 0
    output = llm.generate(prompt)
    used += llm.last_usage.total_tokens
    
    while used < budget_tokens:
        critique = llm.generate(f'Critique: {output}')
        used += llm.last_usage.total_tokens
        if 'DONE' in critique or used > budget_tokens * 0.9: return output
        output = llm.generate(f'Refine: {output} {critique}')
        used += llm.last_usage.total_tokens
    return output

Stop criterion (auto)

def auto_stop_iterate(prompt, llm, max_iter=5):
    prev = llm.generate(prompt)
    for _ in range(max_iter):
        new = llm.generate(f'Improve: {prev}')
        if similarity(prev, new) > 0.95: return new  # 매 converged
        prev = new
    return prev

매 결정 기준

상황 Pattern
Math / reasoning Self-consistency / CoVe
Code Self-refine + execute check
Writing Iterative refinement
Open-ended Best-of-N + judge
Agent task ReAct / Reflexion
Complex search Tree-of-Thoughts

기본값: 매 reasoning = self-consistency (cheap) + CoVe (verify). 매 agent = ReAct + Reflexion. 매 cost-aware budget cap.

🔗 Graph

🤖 LLM 활용

언제: 매 reasoning. 매 high-stakes. 매 agent. 언제 X: 매 simple completion (cost waste).

안티패턴

  • No stop criterion: 매 infinite loop.
  • No cost budget: 매 bill shock.
  • Same prompt every iter: 매 no progress.
  • No diverse sampling (self-consistency): 매 same answer.
  • Skip judge: 매 best-of-N 매 useless.

🧪 검증 / 중복

  • Verified (Madaan Self-Refine 2023, Dhuliawala CoVe 2023, Wang Self-Consistency 2022, Yao ReAct/ToT, Shinn Reflexion 2023).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — patterns + 매 self-refine / CoVe / ReAct / Reflexion / ToT code