pref0 + Mastra

Add preference learning to your Mastra agents. pref0 extracts and serves user preferences to personalize every Mastra workflow.

Quick start

typescript
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");

Why use pref0 with Mastra

TypeScript-native

Mastra and pref0 both work great with TypeScript. Full type safety from preferences to agent instructions.

Workflow integration

Inject preferences at any step in a Mastra workflow. Personalize multi-step agent processes.

Tool-compatible

pref0 preferences work alongside Mastra tools and integrations. No conflicts or ordering issues.

Simple fetch pattern

Get preferences with a single API call before creating your agent. No SDK or plugin required.

Other integrations

Add preference learning to Mastra

Your users are already teaching your agent what they want. pref0 makes sure the lesson sticks.