01Install
Install from npm into your project.
pnpm add @lov3kaizen/agentsea-evaluate02Example
import { EvaluationPipeline, Accuracy, Relevance, EvalDataset } from '@lov3kaizen/agentsea-evaluate';
const pipeline = new EvaluationPipeline({
metrics: [new Accuracy({ type: 'fuzzy' }), new Relevance()],
parallelism: 5,
});
const dataset = new EvalDataset({
items: [
{ id: '1', input: 'What is the capital of France?', expectedOutput: 'Paris' },
{ id: '2', input: 'What is 2 + 2?', expectedOutput: '4' },
],
});
const results = await pipeline.evaluate({ dataset, generateFn: async (input) => await myAgent.run(input) });
console.log(results.summary);03Key API
EvaluationPipeline.evaluate({ dataset, generateFn })Accuracy({ type })RubricJudge({ provider, rubric })ComparativeJudge.compare({ input, responseA, responseB })EvalDataset.filter / sample(count) / split(ratio)04Caveats
- HuggingFace import reads the public datasets-server API. It sends HF_TOKEN for gated datasets. HuggingFace export needs the optional @huggingface/hub package and a write-scoped token.
- Semantic accuracy falls back to fuzzy matching until embeddings are configured.
- Toxicity uses regex patterns, not a model.
- RubricJudge and ComparativeJudge need an LLM provider. Scoring methods for Coherence, Relevance and Faithfulness are not described.
05LLM judges
A judge asks an LLM to score a response. RubricJudge scores one response against criteria you write. ComparativeJudge picks the better of two responses.
import { RubricJudge, ComparativeJudge } from '@lov3kaizen/agentsea-evaluate';
const judge = new RubricJudge({
provider: anthropicProvider, // an LLM provider object you create
rubric: {
criteria: 'Response Quality',
levels: [
{ score: 1, description: 'Poor: incorrect or irrelevant' },
{ score: 3, description: 'Good: correct but incomplete' },
{ score: 5, description: 'Excellent: correct, complete and well explained' },
],
},
});
const comparison = new ComparativeJudge({ provider: openaiProvider, criteria: ['accuracy', 'helpfulness', 'clarity'] });
const winner = await comparison.compare({ input: 'Summarize this article', responseA: modelAOutput, responseB: modelBOutput });06Datasets and Hugging Face
EvalDataset can be filtered, sampled and split. EvalDataset.fromHuggingFace loads rows from a public dataset on the HuggingFace Hub.
import { EvalDataset } from '@lov3kaizen/agentsea-evaluate';
const dataset = await EvalDataset.fromHuggingFace('squad', {
split: 'validation',
subset: 'default',
inputField: 'question',
outputField: 'answers',
contextField: 'context',
limit: 1000,
});
const [train, test] = dataset.split(0.8);07Quality alerts
AlertManager is in the /continuous subpath. Give it a rule for each metric and one or more channels. Each time you feed it a value, it fires the channels when a rule is breached.
import { AlertManager } from '@lov3kaizen/agentsea-evaluate/continuous';
const alerts = new AlertManager({
rules: {
accuracy: { metric: 'accuracy', threshold: 0.8, direction: 'below', severity: 'critical' },
},
cooldownMs: 300000, // suppress repeats for 5 minutes
channels: [{ type: 'slack', webhook: process.env.SLACK_WEBHOOK_URL! }],
});
alerts.check('accuracy', 0.74);slack / webhookemailpagerduty08Human feedback
Import RatingCollector and PreferenceCollector from @lov3kaizen/agentsea-evaluate/feedback. Ratings score a response on named criteria. Preferences record which of two responses an annotator chose.