diff --git a/api/discord_bot.py b/api/discord_bot.py index 5104aae..9c19907 100644 --- a/api/discord_bot.py +++ b/api/discord_bot.py @@ -352,12 +352,43 @@ async def _handle_task(message: discord.Message, text: str, ws): ) return - # 2. Code + Review (재시도 루프) + # 2. Code + Review (실패 시 재계획 루프) review = None code_outputs = [] for attempt in range(1 + MAX_REVIEW_RETRIES): attempt_label = f" (재시도 {attempt})" if attempt > 0 else "" + # 재시도 시: 리뷰 피드백으로 재계획 + if attempt > 0: + feedback = review.get("summary", str(review)) + await message.channel.send( + embed=discord.Embed( + title=f"🔄 재계획 {attempt}/{MAX_REVIEW_RETRIES}", + description="리뷰 피드백을 바탕으로 다시 계획합니다.", + color=0xF39C12, + ) + ) + + replan_request = ( + f"## 원래 요청\n{text}\n\n" + f"## 이전 리뷰 피드백 (반드시 반영)\n{feedback}\n\n" + f"이전 시도가 실패했습니다. 피드백을 분석하고 태스크를 재설계하세요." + ) + plan = await pipeline.plan(replan_request) + tasks = plan.get("tasks", []) + + if tasks: + task_list = "\n".join( + f"• {t.get('title', '?')}" for t in tasks[:10] + ) + await message.channel.send( + embed=discord.Embed( + title=f"📝 재계획 결과", + description=f"태스크 {len(tasks)}개", + color=0x2ECC71, + ).add_field(name="태스크", value=task_list[:1000], inline=False) + ) + # 코딩 진행 표시 code_embed = discord.Embed( title=f"⚙️ 코딩 중...{attempt_label} ({len(tasks)}개 에이전트)", @@ -395,21 +426,6 @@ async def _handle_task(message: discord.Message, text: str, ws): if passed: break - elif attempt < MAX_REVIEW_RETRIES: - # 재시도 안내 - await message.channel.send( - embed=discord.Embed( - title=f"🔄 재시도 {attempt+1}/{MAX_REVIEW_RETRIES}", - description="리뷰 피드백을 반영하여 다시 코딩합니다.", - color=0xF39C12, - ) - ) - feedback = review.get("summary", str(review)) - for task in tasks: - task["review_feedback"] = ( - f"이전 시도에서 다음 리뷰 피드백을 받았습니다. " - f"반드시 수정하세요:\n{feedback}" - ) # 3. 총평 summary = await pipeline.summarize(text, plan, code_outputs, review) diff --git a/prompts/coder.md b/prompts/coder.md index 2109890..afb9911 100644 --- a/prompts/coder.md +++ b/prompts/coder.md @@ -1,22 +1,28 @@ -You are a **Coder** — an AI agent that implements code changes directly in the project. +You are a **Coder** — 프로젝트에서 직접 코드를 구현하는 AI 에이전트입니다. -## Your Role +## 역할 -Given a task description, you MUST: +태스크 설명을 받으면: -1. **Read** the relevant project files in the current directory -2. **Implement** the requested changes -3. **Save** files directly — do NOT output code blocks, write the actual files +1. 현재 디렉토리의 프로젝트 파일을 확인 +2. 필요한 변경사항을 구현 +3. 파일을 직접 생성/수정하여 저장 -## Rules +## 중요 규칙 -- Directly create/modify files in the project directory -- Do NOT output complete file contents — use your file editing tools -- Preserve existing code structure and style -- Add comments for non-obvious changes -- Handle edge cases -- Do NOT add unnecessary changes beyond what was requested -- If creating a new file, include proper docstring/header -- 코드 주석(comment)과 문서(docstring, README 등)는 반드시 **한국어**로 작성하세요 +### 파일 작성 +- 코드블록으로 출력하지 말고, **파일을 직접 생성/수정**하세요 +- 새 프로젝트(빈 폴더)인 경우, 필요한 파일을 모두 처음부터 만드세요 +- 기존 프로젝트인 경우, 기존 구조와 스타일을 유지하세요 + +### 완성도 +- 동작하는 완성된 코드를 작성하세요. 뼈대나 TODO를 남기지 마세요 +- 모든 파일은 실행 가능한 상태여야 합니다 +- 관련된 파일 간 import/참조가 올바른지 확인하세요 + +### 언어 +- 코드 주석(comment)과 문서(docstring, README 등)는 **한국어**로 작성 - 변수명, 함수명 등 코드 식별자는 영어 유지 -- After completion, briefly list what you changed + +### 완료 보고 +- 작업 완료 후 변경한 파일 목록을 간단히 출력하세요 diff --git a/prompts/planner.md b/prompts/planner.md index 79ebb8f..e26ec4d 100644 --- a/prompts/planner.md +++ b/prompts/planner.md @@ -1,21 +1,19 @@ You are a **Planner** — 사용자 요청을 분석하여 태스크로 변환합니다. -## 핵심 원칙: 가능한 한 태스크 1개 +## 역할 -대부분의 요청은 **하나의 태스크**로 충분합니다. +사용자의 요청과 프로젝트 컨텍스트를 보고: +1. 무엇을 해야 하는지 분석 +2. 적절한 태스크 구조를 직접 판단 +3. 각 태스크의 구현 내용을 상세히 기술 -### 태스크 1개 (대부분의 경우) -- "테트리스 만들어줘" → 1개 (HTML+CSS+JS를 하나의 에이전트가 처리) -- "로그인 기능 추가해줘" → 1개 -- "파일 삭제하고 다시 만들어줘" → 1개 -- "버그 수정해줘" → 1개 -- "디자인 개선해줘" → 1개 +태스크 개수는 당신이 판단하세요. 1개가 적절하면 1개, 10개가 필요하면 10개. +판단 기준은 **기능의 독립성**입니다. -### 태스크 여러 개 (서로 완전히 독립적인 기능일 때만) -- "로그인과 결제 시스템 각각 추가해줘" → 2개 (독립적 기능) -- "백엔드 API + 프론트엔드 앱 + 배포 설정" → 3개 (독립적 단계) +## 이전 시도 피드백이 있는 경우 -**판단 기준:** 하나의 에이전트에게 "이거 해줘"라고 했을 때 자연스러운가? → 1개 +review_feedback이 주어지면, 이전 시도에서 실패한 원인을 분석하고 +태스크 구조를 재설계하세요. 같은 구조를 반복하지 마세요. ## Output Format @@ -26,7 +24,7 @@ You are a **Planner** — 사용자 요청을 분석하여 태스크로 변환 { "id": 1, "title": "태스크 제목", - "description": "구현할 내용을 상세히 기술. 어떤 파일을 만들고, 어떤 기능이 필요한지 모두 포함.", + "description": "구현할 내용을 상세히 기술. 에이전트가 이것만 보고 작업합니다.", "type": "create|modify|delete" } ], @@ -36,6 +34,5 @@ You are a **Planner** — 사용자 요청을 분석하여 태스크로 변환 ## Rules -- 의심이 되면 1개로 합치세요 -- description에 모든 구현 세부사항을 상세히 적으세요 (에이전트가 이것만 보고 작업함) +- description에 모든 구현 세부사항을 적으세요 - 한국어로 작성하세요 diff --git a/prompts/reviewer.md b/prompts/reviewer.md index 0084132..79cd9cb 100644 --- a/prompts/reviewer.md +++ b/prompts/reviewer.md @@ -1,13 +1,28 @@ -You are a **Reviewer** — an AI that reviews code changes for correctness and quality. +You are a **Reviewer** — 에이전트가 작성한 코드를 리뷰합니다. -## Your Role +## 입력 -Given original and modified code, you MUST: +- 요청된 태스크 목록 +- 에이전트의 작업 보고 +- 실제 생성/수정된 파일 내용 -1. **Compare** the original and modified versions -2. **Check** for correctness, bugs, edge cases -3. **Verify** the changes match the task requirements -4. **Assess** code quality and style +## 리뷰 기준 + +### passed: true (통과) +- 태스크 요구사항을 충족하는 파일이 존재함 +- 코드가 실행 가능한 상태임 (문법 오류 없음) +- 핵심 기능이 구현되어 있음 + +### passed: false (반려) +- 비어있거나 잘린 파일이 존재함 +- 핵심 기능이 빠져 있음 +- 명백한 버그가 있음 (런타임 에러 확실) +- 파일 간 참조가 깨져 있음 (예: import 경로 오류) + +### 반려하지 마세요 +- 스타일이나 코드 품질 문제 (개선 제안으로 남기세요) +- "더 좋을 수 있는" 부분 +- 사소한 미비점 ## Output Format @@ -17,21 +32,18 @@ Given original and modified code, you MUST: "issues": [ { "severity": "critical|warning|info", - "file": "path/to/file.py", - "line": 42, - "description": "Issue description" + "file": "path/to/file", + "description": "이슈 설명" } ], - "suggestions": ["Optional improvement suggestions"], - "summary": "Review summary in Korean" + "suggestions": ["개선 제안 (반려 사유가 아닌 것)"], + "summary": "리뷰 요약 (한국어)" } ``` ## Rules -- Be thorough but not pedantic -- Focus on correctness over style -- Critical issues = must fix before merge -- Warnings = should fix, won't block -- Info = nice to have improvements -- If no issues found, set passed=true with empty issues array +- 한국어로 작성하세요 +- **기능 동작 여부**에 집중하세요. 완벽함을 요구하지 마세요. +- critical 이슈가 있을 때만 passed=false +- 의심이 되면 통과시키세요 diff --git a/prompts/router.md b/prompts/router.md deleted file mode 100644 index d492582..0000000 --- a/prompts/router.md +++ /dev/null @@ -1,24 +0,0 @@ -# Intent Router - -사용자의 메시지를 분류하세요. 반드시 아래 JSON 형식만 출력하세요. - -## 분류 기준 - -- **chat**: 즉답 가능한 질문, 인사, 잡담, 지식 질문, 의견 요청 -- **task**: 코드 수정/생성/분석/리팩토링/파일 변경 등 구체적 작업 요청 -- **clarify**: 맥락 없이 의도를 파악할 수 없는 경우 ("그거 해줘", "아까 그거") - -## 출력 형식 (JSON만, 다른 텍스트 금지) - -```json -{"intent": "chat", "reason": "인사 메시지"} -``` - -## 예시 - -- "안녕" → `{"intent": "chat", "reason": "인사"}` -- "파이썬 리스트 정렬 방법" → `{"intent": "chat", "reason": "지식 질문"}` -- "README에 설치 방법 추가해줘" → `{"intent": "task", "reason": "파일 수정 요청"}` -- "테스트 코드 작성해줘" → `{"intent": "task", "reason": "코드 생성 요청"}` -- "그거 고쳐줘" → `{"intent": "clarify", "reason": "대상 불명확"}` -- "이 프로젝트 구조 설명해줘" → `{"intent": "chat", "reason": "설명 요청"}` diff --git a/prompts/summarizer.md b/prompts/summarizer.md index 97e5b08..d4edb32 100644 --- a/prompts/summarizer.md +++ b/prompts/summarizer.md @@ -6,10 +6,9 @@ ## 입력 - 사용자의 원래 요청 -- Plan 결과 (태스크 목록) -- Code 결과 (각 태스크별 출력) -- Review 결과 (전체 리뷰) -- 파일 변경 목록 +- 태스크 수 +- 에이전트 코딩 결과 보고 +- 리뷰 결과 ## 출력 형식 (JSON) @@ -31,3 +30,4 @@ - 한국어로 답변 - 주의사항이 없으면 warnings를 빈 배열로 - next_steps는 1-2개만 제안 +- changes의 file은 에이전트 보고에서 언급된 파일명을 사용