text
stringlengths
0
59.1k
toolCallId?: string;
toolName?: string;
arguments?: Record<string, unknown> | null;
content?: string;
stepIndex?: number;
isError?: boolean;
error?: unknown;
}>;
toolResults?: Array<{
toolCallId?: string;
toolName?: string;
result?: unknown;
content?: string;
stepIndex?: number;
isError?: boolean;
error?: unknown;
}>;
userId?: string;
conversationId?: string;
traceId: string;
spanId: string;
timestamp: string;
metadata?: Record<string, unknown>;
rawPayload: AgentEvalPayload;
}
```
Use `input` and `output` for text-based scorers. Access `rawInput` and `rawOutput` for structured data.
Use `messages`, `toolCalls`, and `toolResults` when you need process-level evaluation (for example, checking whether the agent picked the correct tool sequence).
For concrete examples (both built-in and custom), see [Prebuilt Scorers](./prebuilt-scorers.md#evaluating-tool-calls-during-agent-execution).
## Building Custom Scorers
Use `buildScorer` to create scorers with custom logic:
```ts
import { buildScorer } from "@voltagent/core";
const lengthScorer = buildScorer({
id: "response-length",
type: "agent",
label: "Response Length Check",
})
.score(({ payload, params }) => {
const minLength = (params.minLength as number) ?? 50;
const length = payload.output?.length ?? 0;
return {
score: length >= minLength ? 1 : 0,
metadata: { actualLength: length, minLength },
};
})
.reason(({ score, params }) => {
const minLength = (params.minLength as number) ?? 50;
return {
reason:
score >= 1
? `Response meets minimum length of ${minLength} characters.`
: `Response is shorter than ${minLength} characters.`,
};
})
.build();
```
### Builder Methods
#### `.score(fn)`
Defines the scoring function. Return `{ score, metadata? }` or just the numeric score.
```ts
.score(({ payload, params, results }) => {
const match = payload.output?.includes(params.keyword);
return {
score: match ? 1 : 0,
metadata: { keyword: params.keyword, matched: match },
};
})
```
Context properties:
- `payload` - `AgentEvalContext` with input/output
- `params` - Resolved parameters
- `results` - Shared results object for multi-stage scoring
#### `.reason(fn)` (optional)
Generates human-readable explanations. Return `{ reason: string }`.
```ts
.reason(({ score, params }) => ({
reason: score >= 1 ? "Match found" : "No match",
}))
```
#### `.build()`
Returns the `LocalScorerDefinition` object.
## LLM Judge Scorers