Add preference learning to your Mastra agents. pref0 extracts and serves user preferences to personalize every Mastra workflow.
import { Agent } from "@mastra/core/agent";
import { openai } from "@ai-sdk/openai";
const PREF0_API = "https://api.pref0.com";
const PREF0_KEY = process.env.PREF0_API_KEY!;
async function getPreferences(userId: string) {
const res = await fetch(`${PREF0_API}/v1/profiles/${userId}`, {
headers: { Authorization: `Bearer ${PREF0_KEY}` },
});
const { preferences = [] } = await res.json();
return preferences
.filter((p: any) => p.confidence >= 0.5)
.map((p: any) => `- ${p.key}: ${p.value}`)
.join("\n");
}
const learned = await getPreferences("user_abc123");
const agent = new Agent({
name: "Coding Assistant",
instructions: `You are a helpful coding assistant.
Learned user preferences:
${learned}`,
model: openai("gpt-4o"),
});
const response = await agent.generate("Set up a new project for me");Mastra and pref0 both work great with TypeScript. Full type safety from preferences to agent instructions.
Inject preferences at any step in a Mastra workflow. Personalize multi-step agent processes.
pref0 preferences work alongside Mastra tools and integrations. No conflicts or ordering issues.
Get preferences with a single API call before creating your agent. No SDK or plugin required.
Your users are already teaching your agent what they want. pref0 makes sure the lesson sticks.