AgentSea

Package

@lov3kaizen/agentsea-evaluate

Runs an evaluation pipeline over a dataset with built-in metrics, LLM judges and preference export.

v1.2.1On npm

01Install

Install from npm into your project.

BASH
pnpm add @lov3kaizen/agentsea-evaluate

02Example

TS
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 })
Runs the metrics over each dataset item and returns a summary.
Accuracy({ type })
Scores exact or fuzzy matches against the expected output.
RubricJudge({ provider, rubric })
Scores a response against a rubric on a 1 to 5 scale.
ComparativeJudge.compare({ input, responseA, responseB })
Returns the winning response.
EvalDataset.filter / sample(count) / split(ratio)
Selects or splits dataset items.

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.

TS
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.

TS
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.

TS
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 / webhook
Posts the alert to a URL.
email
Sends the alert over SMTP. It needs the optional nodemailer package and a list of recipients.
pagerduty
Opens an incident through the PagerDuty Events API v2, using a routing key.

08Human 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.