text
stringlengths
0
59.1k
id: "length-check",
type: "agent",
label: "Response Length",
})
.score(({ payload }) => {
const length = payload.output?.length ?? 0;
return { score: length > 50 ? 1 : 0 };
})
.build();
```
#### `params`
Static or dynamic parameters passed to the scorer.
**Static:**
```ts
params: {
keyword: "refund",
threshold: 0.8,
}
```
**Dynamic:**
```ts
params: (payload) => ({
keyword: extractKeyword(payload.input),
threshold: 0.8,
});
```
Dynamic params are resolved before each scorer invocation.
#### `sampling`
Override the global sampling policy for this scorer.
```ts
sampling: { type: "ratio", rate: 0.05 } // 5% for this scorer only
```
#### `id`
Override the scorer's default ID. Useful when using the same scorer multiple times with different params.
```ts
scorers: {
keywordRefund: {
scorer: keywordScorer,
id: "keyword-refund",
params: { keyword: "refund" },
},
keywordReturn: {
scorer: keywordScorer,
id: "keyword-return",
params: { keyword: "return" },
},
}
```
#### `onResult`
Callback invoked after scoring completes. Use for custom logging, alerting, or side effects.
```ts
onResult: async (result) => {
if (result.score !== null && result.score < 0.5) {
await alertingService.send({
message: `Low score: ${result.scorerName} = ${result.score}`,
});
}
};
```
## Scorer Context
Scorers receive an `AgentEvalContext` object with these properties:
```ts
interface AgentEvalContext {
agentId: string;
agentName: string;
operationId: string;
operationType: "generateText" | "streamText" | string;
input: string | null; // normalized string
output: string | null; // normalized string
rawInput: unknown; // original input value
rawOutput: unknown; // original output value
messages?: Array<{
id: string;
type: "text" | "tool_call" | "tool_result";
role: "user" | "assistant" | "system" | "tool";
content: string;
name?: string;
arguments?: Record<string, unknown>;
result?: unknown;
}>;
toolCalls?: Array<{