요청 배경
API 기반 에이전트 실행 시 디버깅 및 비용 추적을 위한 로그 정보가 부족합니다.
요청 사항
1. Tool Call 상세 정보 누락
현재:
[INFO] Tool called: run_shell_command
[INFO] Tool result preview: STDOUT: ...
요청:
[INFO] Tool called: run_shell_command
[INFO] Tool args: { "command": "node skills/lineagem-classchange/simulator.js simulate '{...}'" }
[INFO] Tool result preview: STDOUT: ...
문제점:
- 어떤 tool을 호출했는지는 나오지만, 어떤 인자로 실행했는지 안 남음
run_shell_command가 5번 찍히면 어떤 명령어를 실행한 건지 구분 불가
read_file도 어떤 파일을 읽었는지 안 보임
- tool args (인자) 를 같이 로깅해야 디버깅 가능
2. 토큰 사용량 / 비용 정보 누락
현재:
[INFO] Total tool calls across 6 step(s): 5
[INFO] Task completed successfully in 60737ms
요청:
[INFO] Step 1: input_tokens=4406, output_tokens=132, cost=$0.00118
[INFO] Step 2: input_tokens=6337, output_tokens=115, cost=$0.00161
...
[INFO] Total: input_tokens=41431, output_tokens=1192, total_cost=$0.00725
[INFO] Task completed successfully in 60737ms
문제점:
- OpenRouter API 응답에
usage.prompt_tokens, usage.completion_tokens 포함되어 있음
- 현재는 이 정보를 버리고 있어서, 비용 확인하려면 Chrome으로 https://openrouter.ai/logs 직접 접속해야 함
- step별 토큰 수 + 총 비용을 로그에 찍어주면 CLI에서 바로 확인 가능
기술 구현 방향 (초안)
1. Tool Args 로깅
파일: packages/sdk/src/core/providers/MastraAPIProvider.ts:400-408
현재 로깅 코드에 tool args 추가:
// Before
console.log(`[INFO] Tool called: ${toolName}`);
// After
console.log(`[INFO] Tool called: ${toolName}`);
if (toolArgs && Object.keys(toolArgs).length > 0) {
const argsPreview = JSON.stringify(toolArgs).substring(0, 200);
console.log(`[INFO] Tool args: ${argsPreview}${JSON.stringify(toolArgs).length > 200 ? '...' : ''}`);
}
2. Token Usage 및 Cost 로깅
관련 파일:
packages/sdk/src/core/providers/MastraAPIProvider.ts:371-456 - convertResponse()
packages/sdk/src/config/pricing.ts - calculateCost() 이미 구현됨
packages/sdk/src/core/providers/ai-provider.interface.ts:69-73 - AIResponse.usage 이미 정의됨
구현 방향:
-
Vercel AI SDK / Mastra의 fullOutput 객체에서 usage 정보 추출
fullOutput.usage 또는 fullOutput.response.usage 확인
steps[].usage 가 있는지 확인 (multi-step)
-
convertResponse()에서 usage 정보 수집:
// Collect usage from all steps
let totalInputTokens = 0;
let totalOutputTokens = 0;
for (const step of steps) {
if (step.usage) {
totalInputTokens += step.usage.promptTokens || 0;
totalOutputTokens += step.usage.completionTokens || 0;
console.log(`[INFO] Step ${i}: input_tokens=${step.usage.promptTokens}, output_tokens=${step.usage.completionTokens}, cost=$${calculateCost(...)}`);
}
}
// Add to response
response.usage = {
inputTokens: totalInputTokens,
outputTokens: totalOutputTokens,
};
// Final summary
const totalCost = calculateCost(totalInputTokens, totalOutputTokens, this.config.model);
console.log(`[INFO] Total: input_tokens=${totalInputTokens}, output_tokens=${totalOutputTokens}, total_cost=$${totalCost.toFixed(5)}`);
논의 필요 사항
-
Vercel AI SDK usage 데이터 구조 확인
fullOutput.usage 필드 존재 여부
- Multi-step의 경우 step별 usage 추적 방법
- OpenRouter vs 다른 provider의 차이
-
로그 출력 형식
- Tool args 최대 길이 (현재 200자 제안)
- Cost 소수점 자리수 (현재 5자리 제안)
- Step별 로그 vs 최종 요약만
-
환경변수 설정
CREWX_LOG_TOOL_ARGS_MAX_LENGTH 추가?
CREWX_LOG_SHOW_COST=true/false 추가?
-
CLI Provider 호환성
- Claude/Gemini/Copilot도 같은 방식으로 토큰 정보 제공?
- CLI에서 usage 정보 추출 방법?
다음 단계
- 내부 회의: Dev Lead가 팀원들과 기술 구현 방향 논의
- Spike: Vercel AI SDK usage 데이터 구조 확인 (실험)
- 구현: 합의된 방향으로 구현
- 테스트: 실제 OpenRouter API로 검증
- 문서화: README 및 가이드 업데이트
참고
- 요청자: @U08LSF2KNVD (Doha)
- 관련 파일: MastraAPIProvider.ts, ai-provider.interface.ts, pricing.ts
- 기존 인프라: AIResponse.usage, calculateCost() 이미 구현됨
요청 배경
API 기반 에이전트 실행 시 디버깅 및 비용 추적을 위한 로그 정보가 부족합니다.
요청 사항
1. Tool Call 상세 정보 누락
현재:
요청:
문제점:
run_shell_command가 5번 찍히면 어떤 명령어를 실행한 건지 구분 불가read_file도 어떤 파일을 읽었는지 안 보임2. 토큰 사용량 / 비용 정보 누락
현재:
요청:
문제점:
usage.prompt_tokens,usage.completion_tokens포함되어 있음기술 구현 방향 (초안)
1. Tool Args 로깅
파일:
packages/sdk/src/core/providers/MastraAPIProvider.ts:400-408현재 로깅 코드에 tool args 추가:
2. Token Usage 및 Cost 로깅
관련 파일:
packages/sdk/src/core/providers/MastraAPIProvider.ts:371-456- convertResponse()packages/sdk/src/config/pricing.ts- calculateCost() 이미 구현됨packages/sdk/src/core/providers/ai-provider.interface.ts:69-73- AIResponse.usage 이미 정의됨구현 방향:
Vercel AI SDK / Mastra의
fullOutput객체에서 usage 정보 추출fullOutput.usage또는fullOutput.response.usage확인steps[].usage가 있는지 확인 (multi-step)convertResponse()에서 usage 정보 수집:논의 필요 사항
Vercel AI SDK usage 데이터 구조 확인
fullOutput.usage필드 존재 여부로그 출력 형식
환경변수 설정
CREWX_LOG_TOOL_ARGS_MAX_LENGTH추가?CREWX_LOG_SHOW_COST=true/false추가?CLI Provider 호환성
다음 단계
참고