Skip to content

πŸͺ’ Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(v4-migration): enhance upgrade assistant prompts and logic (#15490)

marliessophie1dec1bf25a70
diff --git a/web/src/features/v4-migration/V4MigrationContent.clienttest.tsx b/web/src/features/v4-migration/V4MigrationContent.clienttest.tsx
index bc7af07389..9e142daf4a 100644
--- a/web/src/features/v4-migration/V4MigrationContent.clienttest.tsx
+++ b/web/src/features/v4-migration/V4MigrationContent.clienttest.tsx
@@ -42,9 +42,11 @@ vi.mock("@/src/features/v4-migration/hooks/useV4MigrationData", () => ({
// The plan hook queries tRPC internally; mock it so tests need no provider.
vi.mock("@/src/features/v4-migration/useV4UpgradeAssistantSupport", () => ({
+ V4_CODING_AGENT_PROMPT: "coding-agent-prompt",
useEvalUpgradeAssistantPlan: () => ({
canUseAssistant: false,
- assistantCanUpgrade: false,
+ mode: "outside",
+ showAssistantButton: false,
assistantPrompt: "",
}),
}));
diff --git a/web/src/features/v4-migration/V4MigrationContent.tsx b/web/src/features/v4-migration/V4MigrationContent.tsx
index e8a1fa0e83..159279781a 100644
--- a/web/src/features/v4-migration/V4MigrationContent.tsx
+++ b/web/src/features/v4-migration/V4MigrationContent.tsx
@@ -35,7 +35,10 @@ import {
import { numberFormatter } from "@/src/utils/numbers";
import { formatCompactRelativeTime } from "@/src/utils/dates";
import { useProject } from "@/src/features/projects/hooks";
-import { useEvalUpgradeAssistantPlan } from "@/src/features/v4-migration/useV4UpgradeAssistantSupport";
+import {
+ useEvalUpgradeAssistantPlan,
+ V4_CODING_AGENT_PROMPT,
+} from "@/src/features/v4-migration/useV4UpgradeAssistantSupport";
// Single source of truth for the v4-migration copy and content. Both surfaces
// (side panel and modal) render these components β€” edit copy here only.
@@ -56,12 +59,6 @@ const DEPRECATED_INTEGRATION_MIGRATION_URLS: Record<string, string> = {
"https://langfuse.com/docs/api-and-data-platform/features/export-to-blob-storage#upgrade-path",
};
-const CODING_AGENT_PROMPT = `Migrate this project's Langfuse setup to v4:
-1. Upgrade the Langfuse SDK to the latest major version. Upgrade guide: ${SDK_UPGRADE_URL}
-2. Repoint evals that target trace input/output to observations instead.
-3. Replace calls to deprecated APIs (GET /api/public/traces, GET /api/public/sessions, GET /api/public/metrics) with their v4 replacements.
-Docs: ${V4_DOCS_URL}`;
-
// Copies the agent migration prompt to the clipboard with toast + analytics;
// shared by the panel/modal header CTA and the status page.
export function useCopyMigrationPrompt() {
@@ -69,7 +66,7 @@ export function useCopyMigrationPrompt() {
return async () => {
capture("v4_migration:coding_agent_prompt_copied");
- await navigator.clipboard.writeText(CODING_AGENT_PROMPT);
+ await navigator.clipboard.writeText(V4_CODING_AGENT_PROMPT);
showSuccessToast({
title: "Prompt copied",
description: "Paste it into Cursor, Codex, or another coding agent.",
@@ -438,13 +435,15 @@ export function V4MigrationDetailsContent({
</span>
. Repointing {migrationData.evals.count === 1 ? "it" : "them"}{" "}
at observations or experiments requires minimal changes
- {upgradePlan.assistantCanUpgrade
- ? " β€” the assistant can do it for you"
+ {upgradePlan.showAssistantButton
+ ? upgradePlan.mode === "evals-ready"
+ ? " β€” the assistant can do it for you"
+ : " β€” the assistant can help you choose the upgrade order"
: ""}
.
</p>
<div className="flex items-center gap-3">
- {upgradePlan.assistantCanUpgrade && (
+ {upgradePlan.showAssistantButton && (
<Button
variant="outline"
size="sm"
diff --git a/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts b/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts
index e8eacfe895..859db7a2cf 100644
--- a/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts
+++ b/web/src/features/v4-migration/useV4UpgradeAssistantSupport.ts
@@ -2,23 +2,57 @@ import { useCanUseInAppAgent } from "@/src/ee/features/in-app-agent/components/I
import { useProjectV4SdkData } from "@/src/features/v4-migration/hooks/useV4MigrationData";
import { api } from "@/src/utils/api";
+const V4_SDK_UPGRADE_URL =
+ "https://langfuse.com/docs/observability/sdk/upgrade-path";
+const V4_DOCS_URL = "https://langfuse.com/docs/v4";
+
+/** Prompt for external coding agents (Cursor, Codex, Claude Code) covering
+ * the codebase-side migration work the in-app assistant cannot do. Single
+ * source of truth β€” also embedded verbatim into the assistant prompts below
+ * so users can copy it straight from the assistant's answer. */
+export const V4_CODING_AGENT_PROMPT = `Migrate this project's Langfuse setup to v4:
+1. Upgrade the Langfuse SDK to the latest major version. Upgrade guide: ${V4_SDK_UPGRADE_URL}
+2. Repoint evals that target trace input/output to observations instead.
+3. Replace calls to deprecated APIs (GET /api/public/traces, GET /api/public/sessions, GET /api/public/metrics) with their v4 replacements.
+Docs: ${V4_DOCS_URL}`;
+
const EVAL_UPGRADE_ASSISTANT_PROMPT =
"I want to start my eval upgrade. Use the langfuse skill. Please review this project's deprecated evaluators (trace- and dataset-level), that are both ACTIVE and run on NEW time scope, and help me migrate them to the new targets β€” observations and experiments. Check with me before applying any changes.";
-const UPGRADE_OUTSIDE_PLATFORM_PROMPT =
- "I want to upgrade my Langfuse setup to v4, but parts of it must be upgraded outside of Langfuse, which you cannot do from here. Please tell me to copy the upgrade prompt from the 'Copy prompt for agents' button in the v4 migration panel and run it in my coding editor (Cursor, Codex, Claude Code).";
+const SDK_FIRST_CHOICE_PROMPT = `I want to upgrade my Langfuse setup to v4. My deprecated evaluators can be migrated here with your help, but my SDK upgrade hasn't happened yet β€” that part has to be done in my own codebase. Start by asking me which order I want:
+- Recommended: SDK first. I upgrade the SDK outside Langfuse, then come back and you migrate the evals. If I choose this, give me the coding-editor prompt below to copy.
+- Evals first is also fine. You migrate the evaluators now; the legacy and new evaluators run side by side, and the new ones start producing results as soon as the SDK upgrade lands.
+If I choose evals first, use the langfuse skill, review this project's deprecated evaluators (trace- and dataset-level), that are both ACTIVE and run on NEW time scope, and migrate them to observations and experiments, checking with me before each change.
+
+Coding-editor prompt for the SDK upgrade:
+"""
+${V4_CODING_AGENT_PROMPT}
+"""`;
+
+const UPGRADE_OUTSIDE_PLATFORM_PROMPT = `I want to upgrade my Langfuse setup to v4, but parts of it must be done outside of Langfuse, which you cannot do from here. In your answer, include the following prompt verbatim so I can copy it into my coding editor (Cursor, Codex, Claude Code):
+"""
+${V4_CODING_AGENT_PROMPT}
+"""
+Also ask me whether I would instead like to complete the upgrade by deactivating or deleting all deprecated evaluators β€” if I say yes, help me do that here, confirming each one with me first.`;
+
+export type V4UpgradeAssistantMode =
+ | "evals-ready"
+ | "sdk-first-choice"
+ | "outside";
/**
- * Whether the in-app assistant can complete the remaining v4 upgrade.
- * True only when ALL of:
- * - deprecated evals remain AND the SDK upgrade is already done, and
- * - every remaining legacy eval is trivially repointable (dataset target, or
- * a variable mapping that reads from a single observation) β€” computed
- * server-side as `allAssistantMigratable`.
- *
- * `assistantPrompt` is what the "upgrade now" entry points submit to the
- * assistant: the eval-upgrade instruction when it can do the work, otherwise
- * an instruction to point the user at the coding-agent prompt.
+ * Plans how the in-app assistant participates in the v4 upgrade:
+ * - "evals-ready": deprecated evals remain, all trivially repointable
+ * (dataset targets or single-observation mappings, computed server-side as
+ * `allAssistantMigratable`), and the SDK upgrade is not known to be
+ * pending β†’ the assistant migrates the evals.
+ * - "sdk-first-choice": evals are assistant-migratable and the SDK upgrade is
+ * known to be pending β†’ the assistant asks whether to do the SDK first
+ * (recommended, outside Langfuse) or migrate evals now; legacy and new
+ * evaluators run side by side until the SDK upgrade lands.
+ * - "outside": everything else β†’ the assistant hands over the coding-editor
+ * prompt verbatim and offers deactivating/deleting the deprecated evals
+ * as the alternative.
*/
export function useEvalUpgradeAssistantPlan(params: {
projectId: string | undefined;
@@ -32,20 +66,31 @@ export function useEvalUpgradeAssistantPlan(params: {
{ enabled: params.enabled && Boolean(params.projectId) },
);
- const sdkUpgradeDone =
- sdk.status === "latest" || sdk.status === "otel_realtime";
+ const sdkUpgradeKnownPending =
+ sdk.status === "legacy" ||
+ sdk.status === "otel_header_required" ||
+ sdk.upgradeRequiredCount > 0;
const evalsPending = (evalQuery.data?.traceLevelEvalCount ?? 0) > 0;
- const assistantCanUpgrade =
- canUseAssistant &&
- sdkUpgradeDone &&
- evalsPending &&
+ const allAssistantMigratable =
evalQuery.data?.allAssistantMigratable === true;
+ const mode: V4UpgradeAssistantMode =
+ evalsPending && allAssistantMigratable
+ ? sdkUpgradeKnownPending
+ ? "sdk-first-choice"
+ : "evals-ready"
+ : "outside";
+
return {
canUseAssistant,
- assistantCanUpgrade,
- assistantPrompt: assistantCanUpgrade
- ? EVAL_UPGRADE_ASSISTANT_PROMPT
- : UPGRADE_OUTSIDE_PLATFORM_PROMPT,
+ mode,
+ /** Show the "Migrate with assistant" CTA in the migration panel. */
+ showAssistantButton: canUseAssistant && mode !== "outside",
+ assistantPrompt:
+ mode === "evals-ready"
+ ? EVAL_UPGRADE_ASSISTANT_PROMPT
+ : mode === "sdk-first-choice"
+ ? SDK_FIRST_CHOICE_PROMPT
+ : UPGRADE_OUTSIDE_PLATFORM_PROMPT,
};
}