text
stringlengths
0
59.1k
```
If you want to persist feedback-submitted state in memory after ingestion, use the helper on the returned feedback object:
```ts
const feedbackId = "feedback-id-from-ingestion-response"; // returned by your feedback ingestion API response
if (result.feedback && !result.feedback.isProvided()) {
await result.feedback.markFeedbackProvided({
feedbackId, // optional
});
}
```
Use this helper only for memory-backed conversations (requests that include `userId` and `conversationId`). If those IDs are missing, messages are not persisted, so there is nothing to mark as provided.
### Use a registered key
If the key is already registered, you can omit `feedbackConfig` and the stored config is used.
```ts
const result = await agent.generateText("How was the answer?", {
feedback: { key: "satisfaction" },
});
```
### Streaming feedback metadata
For streaming, VoltAgent attaches feedback metadata to the stream wrapper returned by `agent.streamText`. The `onFinish` callback receives the underlying AI SDK `StreamTextResult`, which does not include VoltAgent feedback metadata. Read feedback from the returned stream wrapper after the stream completes.
```ts
const stream = await agent.streamText("Explain this trace", {
feedback: true,
onFinish: async (result) => {
// result is the AI SDK StreamTextResult (no VoltAgent feedback here)
console.log(await result.text);
},
});
for await (const _chunk of stream.textStream) {
// consume stream output
}
console.log(stream.feedback);
```
## Automated feedback with eval scorers
You can run LLM or heuristic scorers and persist the result as feedback without manual `fetch` calls. The `onResult` callback receives a `feedback` helper with `feedback.save(...)`. The `key` is required and the trace id is taken from the scorer result.
```ts
import { Agent, buildScorer } from "@voltagent/core";
import { openai } from "@ai-sdk/openai";
import { z } from "zod";
const judgeAgent = new Agent({
name: "satisfaction-judge",
model: openai("gpt-4o-mini"),
instructions: "Return JSON with score (0-1), label, and optional reason.",
});
const judgeSchema = z.object({
score: z.number().min(0).max(1),
label: z.string(),
reason: z.string().optional(),
});
const satisfactionScorer = buildScorer({
id: "satisfaction-judge",
label: "Satisfaction Judge",
})
.score(async ({ payload }) => {
const prompt = `Score user satisfaction (0-1) and label it.
User: ${payload.input}
Assistant: ${payload.output}`;
const response = await judgeAgent.generateObject(prompt, judgeSchema);
return {
score: response.object.score,
metadata: {
label: response.object.label,
reason: response.object.reason ?? null,
},
};
})
.build();
const agent = new Agent({
name: "support-agent",
model: openai("gpt-4o-mini"),
eval: {
scorers: {
satisfaction: {
scorer: satisfactionScorer,
onResult: async ({ result, feedback }) => {
await feedback.save({
key: "satisfaction",
value: result.metadata?.label ?? null,
score: result.score ?? null,
comment: result.metadata?.reason ?? null,
feedbackSourceType: "model",