CI의 득점자 실행
CI 파이프라인에서 득점자를 실행하면 시간 경과에 따른 Agent 품질을 측정하기 위한 수량화 가능한 측정항목이 제공됩니다. 그만큼runEvals함수는 Agent 또는 Workflow를 통해 여러 테스트 사례를 처리하고 집계 점수를 반환합니다.
기본 설정기본 설정에 대한 직접 링크
Vitest, Jest 또는 Mocha처럼 ESM 모듈을 지원하는 모든 테스트 프레임워크를 사용할 수 있습니다.
테스트 케이스 만들기테스트 케이스 만들기에 대한 직접 링크
여러 테스트 사례에 대해 Agent를 평가하려면 runEvals를 사용하세요. 이 함수는 데이터 항목 배열을 받으며, 각 항목에는 input과 채점자 검증에 사용할 선택적 groundTruth가 포함됩니다.
src/mastra/agents/weather-agent.test.ts
import { describe, it, expect } from 'vitest'
import { createScorer, runEvals } from '@mastra/core/evals'
import { weatherAgent } from './weather-agent'
import { locationScorer } from '../scorers/location-scorer'
describe('Weather Agent Tests', () => {
it('should correctly extract locations from queries', async () => {
const result = await runEvals({
data: [
{
input: 'weather in Berlin',
groundTruth: { expectedLocation: 'Berlin', expectedCountry: 'DE' },
},
{
input: 'weather in Berlin, Maryland',
groundTruth: { expectedLocation: 'Berlin', expectedCountry: 'US' },
},
{
input: 'weather in Berlin, Russia',
groundTruth: { expectedLocation: 'Berlin', expectedCountry: 'RU' },
},
],
target: weatherAgent,
scorers: [locationScorer],
})
// Assert aggregate score meets threshold
expect(result.scores['location-accuracy']).toBe(1)
expect(result.summary.totalItems).toBe(3)
})
})
결과 이해결과 이해에 대한 직접 링크
runEvals 함수는 다음 항목을 포함한 객체를 반환합니다.
scores: 모든 테스트 케이스에 걸쳐 각 채점자의 평균 점수summary.totalItems: 처리된 총 테스트 케이스 수
{
scores: {
'location-accuracy': 1.0, // Average score across all items
'another-scorer': 0.85
},
summary: {
totalItems: 3
}
}
여러 테스트 시나리오여러 테스트 시나리오에 대한 직접 링크
다양한 평가 시나리오에 대해 별도의 테스트 사례를 만듭니다.
src/mastra/agents/weather-agent.test.ts
describe('Weather Agent Tests', () => {
const locationScorer = createScorer({/* ... */})
it('should handle location disambiguation', async () => {
const result = await runEvals({
data: [
{
input: 'weather in Berlin',
groundTruth: {/* ... */},
},
{
input: 'weather in Berlin, Maryland',
groundTruth: {/* ... */},
},
],
target: weatherAgent,
scorers: [locationScorer],
})
expect(result.scores['location-accuracy']).toBe(1)
})
it('should handle typos and misspellings', async () => {
const result = await runEvals({
data: [
{
input: 'weather in Berln',
groundTruth: { expectedLocation: 'Berlin', expectedCountry: 'DE' },
},
{
input: 'weather in Parris',
groundTruth: { expectedLocation: 'Paris', expectedCountry: 'FR' },
},
],
target: weatherAgent,
scorers: [locationScorer],
})
expect(result.scores['location-accuracy']).toBe(1)
})
})
다음 단계다음 단계에 대한 직접 링크
- 커스텀 채점자 만들기 자세히 알아보기
- 기본 제공 채점자 살펴보기
- Memory가 활성화된 Agent를 대상으로 채점자 실행하기
- runEvals API 레퍼런스 읽기