text
stringlengths
0
59.1k
type: "agent",
})
.score(({ payload, params }) => {
const keyword = params.keyword as string;
const matched = payload.output?.toLowerCase().includes(keyword.toLowerCase());
return { score: matched ? 1 : 0 };
})
.build();
// Usage:
scorers: {
keyword: {
scorer: keywordScorer,
params: { keyword: "refund" },
},
}
```
## VoltOps Integration
When a VoltOps client is configured globally, live scorer results are forwarded automatically:
```ts
import VoltAgent, { Agent, VoltAgentObservability } from "@voltagent/core";
import { VoltOpsClient } from "@voltagent/sdk";
const voltOpsClient = new VoltOpsClient({
publicKey: process.env.VOLTAGENT_PUBLIC_KEY,
secretKey: process.env.VOLTAGENT_SECRET_KEY,
});
const observability = new VoltAgentObservability();
new VoltAgent({
agents: { support: agent },
observability,
voltOpsClient, // enables automatic forwarding
});
```
The framework creates evaluation runs, registers scorers, appends results, and finalizes summaries. Each batch of scores (per agent interaction) becomes a separate run in VoltOps.
## Sampling Strategies
### Ratio Sampling
Sample a percentage of interactions:
```ts
sampling: { type: "ratio", rate: 0.1 } // 10% of traffic
```
Use for high-volume agents where scoring every interaction is expensive.
### Count Sampling
Sample every Nth interaction:
```ts
sampling: { type: "count", rate: 100 } // every 100th interaction
```
Use when you need predictable sampling intervals or rate-limiting.
### Per-Scorer Sampling
Override sampling for specific scorers:
```ts
eval: {
sampling: { type: "ratio", rate: 1 }, // default: score all
scorers: {
moderation: {
scorer: moderationScorer,
sampling: { type: "ratio", rate: 1 }, // always run moderation
},
helpfulness: {
scorer: helpfulnessScorer,
sampling: { type: "ratio", rate: 0.05 }, // 5% for expensive LLM judge
},
},
}
```
## Error Handling
If a scorer throws an exception, the result is marked `status: "error"` and the error message is captured in `errorMessage`. Other scorers continue executing.
```ts
.score(({ payload, params }) => {
if (!params.keyword) {
throw new Error("keyword parameter is required");
}
// ...
})
```
The error appears in observability storage and VoltOps telemetry.
## Best Practices