멀티 모델 전략
여러 AI 모델을 상황에 맞게 선택하고 비용을 최적화하는 방법을 알아봅니다.
모델 비교
| 모델 | 비용 | 성능 | 사용 사례 |
|---|---|---|---|
| Haiku | 낮음 | 빠름 | 단순 질의, 요약 |
| Sonnet | 중간 | 균형 | 일반 작업, 코드 작성 |
| Opus | 높음 | 최고 | 복잡한 분석, 창의 작업 |
상세 비교
| 특성 | Haiku | Sonnet | Opus |
|---|---|---|---|
| 응답 속도 | 가장 빠름 | 빠름 | 상대적으로 느림 |
| 비용 | $0.25/1M 토큰 | $3/1M 토큰 | $15/1M 토큰 |
| 분석 능력 | 단순 | 중간 | 복잡 |
| 창의성 | 낮음 | 중간 | 높음 |
모델 선택 가이드
작업 유형별 모델 선택
agents:
defaults:
model: "claude-sonnet-4-20250514"
taskModels:
simple:
model: "claude-haiku-4-20250514"
useCases:
- "단순 질의 응답"
- "텍스트 요약"
- "데이터 추출"
standard:
model: "claude-sonnet-4-20250514"
useCases:
- "일반 대화"
- "코드 작성"
- "문서 생성"
complex:
model: "claude-opus-4-20250514"
useCases:
- "복잡한 분석"
- "창의적 작업"
- "다단계 추론"
동적 모델 선택
async execute(context) {
const complexity = this.assessComplexity(context.message.text);
const model = complexity === 'high' ? 'claude-opus-4-20250514' :
complexity === 'medium' ? 'claude-sonnet-4-20250514' :
'claude-haiku-4-20250514';
const result = await this.executeWithModel(model, context);
return { success: true, model, result };
},
assessComplexity(text) {
const indicators = {
high: ['분석해', '비교해', '전략', '아키텍처'],
medium: ['작성해', '만들어', '코드', '함수'],
low: ['뭐야', '설명', '요약', '알려줘']
};
for (const [level, keywords] of Object.entries(indicators)) {
if (keywords.some(kw => text.includes(kw))) {
return level;
}
}
return 'low';
}
사용 사례별 추천
단순 질문 ("오늘 날씨 어때?") → Haiku
요약 ("이 글을 요약해줘") → Haiku
일반 대화 ("코드 설명해줘") → Sonnet
문서 작성 ("README 작성해줘") → Sonnet
복잡한 분석 ("이 데이터를 분석하고 인사이트 도출") → Opus
창의 작업 ("혁신적인 아이디어 제안") → Opus
비용 최적화
캐싱 전략
async execute(context) {
const cacheKey = this.hash(context.message.text);
const cached = await this.getCache(cacheKey);
if (cached) {
return { success: true, cached: true, result: cached };
}
const result = await this.callModel(context);
if (this.isFrequentQuestion(context.message.text)) {
await this.setCache(cacheKey, result, 3600);
}
return { success: true, cached: false, result };
}
배치 처리
여러 작업을 하나의 요청으로 묶어 비용을 절감합니다:
const prompt = tasks.map((t, i) => `작업 ${i + 1}: ${t}`).join('\n\n');
const batched = await this.callModel({
messages: [{ role: 'user', content: `다음 작업들을 처리하세요:\n\n${prompt}` }]
});
컨텍스트 최소화
// 필수 컨텍스트만 포함
const prompt = `
관련 요약: ${relevantSummary}
현재 질문: ${userQuery}
`;
모범 사례
간단한 작업은 Haiku를 사용합니다:
// 비용 효율적
model: "claude-haiku-4-20250514" // $0.25/1M 토큰
// 불필요한 과도한 모델 사용 지양
// model: "claude-opus-4-20250514" // $15/1M 토큰
캐싱을 활용합니다:
const cached = await this.getCache(prompt);
if (cached) return cached;
const result = await this.callModel(prompt);
await this.setCache(prompt, result);
참고: