⏱️ 예상 읽기 시간: 10분

서론

Mini SWE-Agent는 단 100줄의 Python 코드로 GitHub 이슈를 자동으로 해결하는 혁신적인 AI 도구입니다. SWE-agent의 복잡함을 제거하고 핵심만 남긴 결과, Claude Sonnet 4와 함께 SWE-bench에서 65%의 놀라운 성능을 달성했습니다.

왜 Mini SWE-Agent인가?

  • 극도의 단순함: 복잡한 설정 없이 즉시 사용
  • 강력한 성능: SWE-bench 65% 달성
  • 완전한 투명성: bash만 사용, 도구 추상화 없음
  • 어디서나 실행: Docker, 클라우드, 로컬 환경 지원

핵심 아키텍처

혁신적인 설계 철학

# Mini SWE-Agent의 핵심 - 단 100줄!
class MiniAgent:
    def __init__(self, model, environment):
        self.model = model  # 어떤 LLM이든 사용 가능
        self.env = environment  # bash 셸 환경
        self.history = []  # 완전히 선형적인 히스토리
    
    def solve_issue(self, task):
        """GitHub 이슈 해결"""
        self.history.append(f"Task: {task}")
        
        while not self.is_complete():
            # 1. 모델에게 다음 행동 요청
            action = self.model.get_action(self.history)
            
            # 2. subprocess.run으로 독립 실행
            result = subprocess.run(action, shell=True, capture_output=True)
            
            # 3. 결과를 히스토리에 추가
            self.history.append(f"Action: {action}")
            self.history.append(f"Result: {result.stdout}")

기존 SWE-agent와의 차이점

구분 SWE-agent Mini SWE-Agent
코드 길이 수만 줄 100줄
도구 사용 복잡한 도구 세트 bash만 사용
실행 방식 상태 유지 세션 subprocess.run 독립 실행
히스토리 복잡한 처리 완전 선형 구조
배포 복잡한 설정 즉시 배포

설치 및 설정

1. 빠른 시작 (권장)

# uvx를 사용한 즉시 실행
pip install uv
uvx mini-swe-agent

# 시각적 UI 버전
uvx mini-swe-agent -v

2. 기존 환경 설치

# 패키지 설치
pip install mini-swe-agent

# 실행
mini

# 시각적 UI
mini -v

3. 소스에서 설치

git clone https://github.com/SWE-agent/mini-swe-agent.git
cd mini-swe-agent
pip install -e .
mini

API 키 설정

지원 모델

  • Claude Sonnet 4 (권장, 65% 성능)
  • GPT-4o
  • GPT-4 Turbo
  • Gemini Pro

환경 변수 설정

# Anthropic Claude (최고 성능)
export ANTHROPIC_API_KEY="your-api-key"

# OpenAI GPT
export OPENAI_API_KEY="your-api-key"

# 또는 .env 파일에 저장
echo "ANTHROPIC_API_KEY=your-api-key" > .env

실제 사용법

1. 기본 사용 - 간단한 코딩 작업

mini

입력 예시:

> Create a Python web scraper for e-commerce product prices

실행 과정:

🔍 Analyzing task...
📝 Planning implementation...

Action: pip install requests beautifulsoup4
Result: Successfully installed...

Action: cat > scraper.py << 'EOF'
import requests
from bs4 import BeautifulSoup
import json

class ProductScraper:
    def __init__(self):
        self.session = requests.Session()
        self.session.headers.update({
            'User-Agent': 'Mozilla/5.0...'
        })
    
    def scrape_product(self, url):
        response = self.session.get(url)
        soup = BeautifulSoup(response.content, 'html.parser')
        
        # 가격 추출 로직
        price_selectors = [
            '.price', '#price', '[data-price]',
            '.amount', '.cost'
        ]
        
        for selector in price_selectors:
            price_elem = soup.select_one(selector)
            if price_elem:
                return self.clean_price(price_elem.text)
        
        return None
    
    def clean_price(self, price_text):
        import re
        # 숫자와 소수점만 추출
        return re.sub(r'[^\d.]', '', price_text)

if __name__ == "__main__":
    scraper = ProductScraper()
    price = scraper.scrape_product("https://example-store.com/product")
    print(f"Product price: ${price}")
EOF

Action: python scraper.py
Result: Product price: $29.99

✅ Web scraper created successfully!

2. GitHub 이슈 해결

# GitHub 저장소로 이동
cd your-project

# Mini SWE-Agent 실행
mini

# 이슈 해결 요청
> Fix the authentication bug where JWT tokens expire too quickly

AI 에이전트의 해결 과정:

  1. 코드베이스 탐색: 인증 관련 파일 찾기
  2. 버그 분석: JWT 토큰 만료 시간 확인
  3. 수정 구현: 토큰 만료 시간 조정
  4. 테스트 실행: 수정사항 검증
  5. 문서 업데이트: 변경사항 기록

3. 시각적 UI 사용

mini -v

시각적 UI 특징:

  • 실시간 진행상황 표시
  • 파일 변경사항 하이라이팅
  • 에러 로그 색상 구분
  • 다중 작업 관리

Python API 활용

프로그래밍 방식 사용

from minisweagent import DefaultAgent, LitellmModel, LocalEnvironment

# 에이전트 설정
agent = DefaultAgent(
    model=LitellmModel(
        model_name="claude-3-5-sonnet-20241022",
        api_key="your-anthropic-api-key"
    ),
    environment=LocalEnvironment()
)

# 작업 실행
result = agent.run("Implement user authentication with JWT")

print(f"Success: {result.success}")
print(f"Final message: {result.final_message}")
print(f"Files changed: {len(result.file_changes)}")

배치 처리

import asyncio

async def process_multiple_tasks():
    """여러 작업을 동시에 처리"""
    
    tasks = [
        "Add unit tests for the user model",
        "Implement password reset functionality", 
        "Add email validation to registration",
        "Create API documentation"
    ]
    
    agents = [create_agent() for _ in tasks]
    
    # 병렬 실행
    results = await asyncio.gather(*[
        agent.run_async(task) 
        for agent, task in zip(agents, tasks)
    ])
    
    # 결과 요약
    success_count = sum(r.success for r in results)
    print(f"✅ {success_count}/{len(tasks)} tasks completed successfully")
    
    return results

# 실행
results = asyncio.run(process_multiple_tasks())

SWE-bench 평가

벤치마크 실행

# SWE-bench 데이터셋으로 평가
mini-swe-agent --batch \
  --dataset swe-bench-verified \
  --model claude-3-5-sonnet-20241022 \
  --output-dir ./results

성능 결과

Claude Sonnet 4 기준:

  • 전체 성공률: 65%
  • Python 프로젝트: 70%
  • JavaScript 프로젝트: 60%
  • 평균 해결 시간: 8.5분

다른 모델 비교:

Claude Sonnet 4:    65% (권장)
GPT-4o:            58%
GPT-4 Turbo:       52%
GPT-3.5 Turbo:     35%

실제 프로젝트 적용

1. 오픈소스 기여

# 실제 오픈소스 프로젝트
git clone https://github.com/requests/requests.git
cd requests

# 이슈 해결
mini

> Improve error handling for connection timeouts in requests library

성공 사례:

  • FastAPI: 문서 개선 및 예제 추가
  • Pandas: 성능 최적화 및 버그 수정
  • Django: 보안 패치 및 테스트 추가

2. CI/CD 통합

# .github/workflows/ai-review.yml
name: AI Code Review

on: [pull_request]

jobs:
  ai-review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: AI Code Review
        run: |
          pip install mini-swe-agent
          mini "Review this PR for code quality and security issues"
        env:
          ANTHROPIC_API_KEY: $

3. 레거시 코드 리팩토링

# 자동 리팩토링 스크립트
def refactor_legacy_code(project_path):
    agent = DefaultAgent(
        model=LitellmModel(model_name="claude-3-5-sonnet-20241022"),
        environment=LocalEnvironment()
    )
    
    tasks = [
        "Add type hints to all functions",
        "Replace deprecated APIs with modern equivalents",
        "Add comprehensive error handling",
        "Optimize database queries",
        "Add unit tests for critical functions"
    ]
    
    for task in tasks:
        result = agent.run(f"In {project_path}, {task}")
        print(f"✅ {task}: {'Success' if result.success else 'Failed'}")

# 실행
refactor_legacy_code("./legacy_project")

성능 최적화

1. 모델별 최적 설정

MODEL_CONFIGS = {
    "claude-3-5-sonnet-20241022": {
        "temperature": 0.1,
        "max_tokens": 4096,
        "best_for": ["complex_reasoning", "debugging"]
    },
    
    "gpt-4o": {
        "temperature": 0.2,
        "max_tokens": 2048,
        "best_for": ["rapid_prototyping", "testing"]
    }
}

2. 비용 최적화

class CostOptimizer:
    def estimate_cost(self, task, model):
        complexity = self.analyze_complexity(task)
        tokens = complexity * 500
        cost = tokens * self.get_model_cost(model)
        return cost
    
    def recommend_model(self, task, budget):
        """예산 내 최적 모델 추천"""
        for model in ["claude-3-5-sonnet", "gpt-4o", "gpt-3.5-turbo"]:
            cost = self.estimate_cost(task, model)
            if cost <= budget:
                return model
        return "gpt-3.5-turbo"  # 최저가 모델

문제 해결

일반적인 문제들

API 키 오류:

# 환경 변수 확인
echo $ANTHROPIC_API_KEY

# API 키 테스트
python -c "
from anthropic import Anthropic
client = Anthropic()
print('API key valid!')
"

실행 권한 문제:

# 실행 권한 부여
chmod +x $(which mini)

# Python 경로 확인
which python
python --version

Docker 환경:

# Docker에서 실행
docker run -it --rm \
  -v $(pwd):/workspace \
  -e ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
  python:3.11 bash -c "
    pip install mini-swe-agent && 
    cd /workspace && 
    mini
  "

결론

Mini SWE-Agent는 복잡함을 제거하고 본질에 집중한 혁신적인 접근을 보여줍니다. 100줄의 코드로 65% SWE-bench 성능을 달성한 것은 AI 에이전트의 새로운 가능성을 제시합니다.

핵심 가치

  1. 단순성: 복잡한 도구 없이 bash만으로 모든 작업
  2. 투명성: 완전히 선형적인 히스토리로 디버깅 용이
  3. 확장성: subprocess.run 기반으로 어디서나 실행
  4. 실용성: 즉시 사용 가능한 개발 도구

활용 분야

  • 개발 자동화: GitHub 이슈 해결, 코드 리뷰
  • 레거시 현대화: 오래된 코드베이스 리팩토링
  • 연구 개발: SWE-bench 실험, 모델 비교
  • 교육: AI 에이전트 학습용 베이스라인

지금 바로 uvx mini-swe-agent로 시작해보세요. 단 몇 분 만에 AI가 코딩하는 마법을 경험할 수 있습니다! 🚀


참고 자료: