text
stringlengths
0
59.1k
name: "offline-evals-support",
instructions: "You are a helpful assistant. Answer questions very short.",
model: openai("gpt-4o-mini"),
});
const result = await supportAgent.generateText(item.input);
return {
output: result.text,
};
},
scorers: [
{
id: "my-custom-scorer-id",
scorer: scorers.levenshtein,
threshold: 0.5,
},
],
passCriteria: [
{
type: "passRate",
min: 1.0, // All items must pass
scorerId: "my-custom-scorer-id", // Only consider this scorer
},
{
type: "meanScore",
min: 0.5, // Average score must be at least 0.5
},
],
});
```
Pass criteria are evaluated **after all items complete**. If any criterion fails, the experiment result shows which criteria were not met. You can also set `severity: "warn"` on criteria that shouldn't fail the run but should be reported.
## Step 5: Run Your Experiment
There are two ways to execute experiments: programmatically via the API or through the VoltAgent CLI.
### Option 1: Run with the API
Use `runExperiment` to execute your experiment programmatically:
```ts
import { runExperiment } from "@voltagent/evals";
import experiment from "./experiments/offline.experiment";
const result = await runExperiment(experiment, {
onProgress: ({ completed, total }) => {
const label = total !== undefined ? `${completed}/${total}` : `${completed}`;
console.log(`[with-offline-evals] processed ${label} items`);
},
});
console.log("Summary:", {
success: result.summary.successCount,
failures: result.summary.failureCount,
errors: result.summary.errorCount,
meanScore: result.summary.meanScore,
passRate: result.summary.passRate,
});
```
**API Options:**
- `concurrency` - Number of items processed in parallel (default: 1)
- `signal` - AbortSignal to cancel the run
- `voltOpsClient` - VoltOps client instance for telemetry and cloud datasets (VoltOpsClient or VoltOpsRestClient)
- `onProgress` - Callback invoked after each item with `{ completed, total? }`
- `onItem` - Callback invoked after each item with `{ index, item, result, summary }`
Example with all options:
```ts
import { VoltOpsClient } from "@voltagent/sdk";
const result = await runExperiment(experiment, {
concurrency: 4,
signal: abortController.signal,
voltOpsClient: new VoltOpsClient({
publicKey: process.env.VOLTAGENT_PUBLIC_KEY,
secretKey: process.env.VOLTAGENT_SECRET_KEY,
}),
onProgress: ({ completed, total }) => {
console.log(`Processed ${completed}/${total ?? "?"} items`);
},
onItem: ({ index, result }) => {
console.log(`Item ${index}: ${result.status}`);
},
});
```
### Option 2: Run with the CLI
The VoltAgent CLI provides a convenient way to run experiments from the command line:
```bash
pnpm volt eval run --experiment ./src/experiments/offline.experiment.ts
```
**CLI Options:**
- `--experiment <path>` (required) - Path to the experiment module